Search code examples
jqueryhtmltagsstrip

Strip specific tag from parent (jQuery)


HTML:

<div class="featured">
    <h4><a href="#">Title 1</a></h4>
    <a href="#"><img src="image.png" class="image"/></a>
    <p><a href="#"></a><br />
    Description goes here</p>
</div>

<div class="featured">
    <h4><a href="#">Title 2</a></h4>
    <a href="#"><img src="image.png" class="image"/></a>
    <p><a href="#"></a></p>
    <p>Description goes here</p>
</div>

.. How do I strip out all <p> tags from .featured?

Thanks


Solution

  • This works, but only because your paragraph elements are at the end of your divs:

    $(".featured p").each(function(){
        var content = $(this).html();
        $(this).parent().append(content);
        $(this).remove();
    });