Search code examples
jqueryjquery-selectorsdom-traversal

Removing an element after a div with Jquery


I would like to remove the p tag that directly follows a div using jquery. Here is my HTML:

<div class="fbcommentbox"></div>
<p>Powered by <a href="http://pleer.co.uk/wordpress/plugins/facebook-comments/">Facebook Comments</a></p>

So in this case, all content inside the <p> tags will be set to display:none.

This seems like it would be VERY simple to do in jquery but I cannot seem to put my finger on it. Any help would be great. Thanks!


Solution

  • $('div.fbcommentbox + p').hide();
    
    • hide() sets display: none.
    • remove() removes the element from the DOM.

    Pick the one you need.