For instance, the code is:
<ul>
<li><strong>This is a list header.</strong> And I want this text to disappear because this is not a list header!</li>
</ul>
And the JavaScript code is:
$('ul li').hide();
$('ul li strong').fadeIn();
What I am trying to achieve is to hide the text that is not inside <strong>
.
The siblings() is an inbuilt method in jQuery which is used to find all siblings elements of the selected element. The siblings are those having same parent element in DOM Tree.
The best way is to . clone() your object, . remove() all of its . children() , then go back to the object using .
jQuery prev() Method The prev() method returns the previous sibling element of the selected element. Sibling elements are elements that share the same parent.
The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field. Syntax: $(selector). select(function);
Try to wrap that text inside a span
and do,
HTML:
<ul>
<li>
<strong>This is a list header.</strong>
<span>And I want this text to disappear because this is not a list header!</span>
</li>
</ul>
JS:
$('ul li >').hide().filter('strong').fadeIn();
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