Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 531
JCHASE11 Avatar asked Jun 27 '11 18:06

JCHASE11


People also ask

How do you delete something in jQuery?

To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.

What is the difference between remove () and detach () methods in jQuery?

remove() removes the matched elements from the DOM completely. detach() is like remove() , but keeps the stored data and events associated with the matched elements.

How can remove TD value in jQuery?

closest('td'). prev(). children(). remove(); });

How do I remove all elements from a div?

The empty() method removes all child nodes and content from the selected elements.


2 Answers

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

Pick the one you need.

like image 192
rid Avatar answered Sep 27 '22 21:09

rid


This should work:

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

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

like image 43
Ben Everard Avatar answered Sep 27 '22 20:09

Ben Everard