rationalboss
rationalboss

Reputation: 5389

Is it possible to select text in jquery context from a sibling element context?

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>.

Upvotes: 5

Views: 60

Answers (2)

deviloper
deviloper

Reputation: 7240

Just like Rajaprabhu said, wrap that text inside a span and:

<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>

and the js:

$('ul li >').filter(':not(strong)').hide();

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67197

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();

DEMO

Upvotes: 5

Related Questions