Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery, find li class name (inside ul)

I have ul with a number of li inside. All li have an id "#category" but different classes (like ".tools", ".milk", ".apple").

Using jQuery. I do :

$("li#category").click(function(){ some_other_thing ( .... )});

now i have to put a li's class "name" — (a string indeed) inside the some_other_thing() function instead of ....

How it can be done?

like image 921
There Are Four Lights Avatar asked Aug 30 '10 22:08

There Are Four Lights


2 Answers

$(this).attr('class')
like image 112
Thinker Avatar answered Oct 18 '22 22:10

Thinker


Beware that id must be unique! You're suggesting that each li element has the same id. You might want to replace it with a class, e.g.:

<ul>
  <li class="category tools" />
  <li class="category milk" />
</ul>

Then select with:

$('li.category').click(function(){});
like image 21
Paul Lammertsma Avatar answered Oct 18 '22 21:10

Paul Lammertsma