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
  • 3,418
  • 5
  • 38
  • 63

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
  • 312,895
  • 29
  • 395
  • 388
1

You can use selector like this

var item = $('ul li.special')
Sachin
  • 40,216
  • 7
  • 90
  • 102