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!
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.
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.
closest('td'). prev(). children(). remove(); });
The empty() method removes all child nodes and content from the selected elements.
$('div.fbcommentbox + p').hide();
hide()
sets display: none
.remove()
removes the element from the DOM.Pick the one you need.
This should work:
$('.fbcommentbox').next('p').remove();
We select the div, then use next
to get the next element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With