Removing an element after a div with Jquery

JCHASE11 picture JCHASE11 · Jun 27, 2011 · Viewed 52.5k times · Source

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!

Answer

Ben Everard picture Ben Everard · Jun 27, 2011

This should work:

$('.fbcommentbox').next('p').remove();

We select the div, then use next to get the next element.