0

I have a group of items like this:

<ul>
  <li></li>
  <li></li>
  <li></li>
  <li class="special"></li>
</ul>

and I have a jquery variable which is:

item = $('ul li')

how do I select the 'li' with the special class, using the variable. So that I could for example do something like this:

$(<item with special class>).click();
Matt Coady
  • 2,834
  • 5
  • 35
  • 58

2 Answers2

4

If the elements are at root level, meaning it's the LI that has the class, not any of it's children, you would filter the collection against that selector.

var item    = $('ul li')
var special = item.filter('.special')
adeneo
  • 303,455
  • 27
  • 380
  • 377
1

You can use selector like this

var item = $('ul li.special')
Sachin
  • 39,043
  • 7
  • 86
  • 102