Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a li with a specific class?

<ul id="attached_deals_tab" class="nav nav-tabs">
  <li class="active">
    <a data-toggle="tab" href="#Test1">Test1</a>
  </li>
  <li class="">
    <a data-toggle="tab" href="#Test2">Test2</a>
  </li>
</ul>

With a jquery like this, I could say get me all list items:

$('#attached_deals_tab li');

But how can I say show me only the li that has class="active" ? In one line please.

I know how to negate it:

$('#attached_deals_tab li:not(.active)');

But not the other way around...

like image 356
Houman Avatar asked Sep 26 '12 14:09

Houman


People also ask

Can an LI have a class?

Classes (i.e. classnames) are used for styling the li element. Multiple classnames are separated by a space. JavaScript uses classes to access elements by classname.

How do I add a class to click in Li?

$('li a'). click(function() { $('li a'). removeClass('selected'); $(this). addClass('selected'); });


1 Answers

$('#attached_deals_tab li.active');
like image 75
jholloman Avatar answered Oct 12 '22 13:10

jholloman