Reputation: 11
the element can change according to users' action, that's why I use on()
$(document).ready(function(){
$(document).on('click','li', function(){
if($('li').hasClass()){
//do something <-- but it return true (boolean)
}
});
Upvotes: 1
Views: 40
Reputation: 4081
Use this :
$(document).ready(function(){
$(document).on('click','li', function(){
if(if ($('li').hasClass('yourclassname'))){
//do something <-- but it return true (boolean)
}
});
Upvotes: 0
Reputation: 382434
You probably want
$(document).on('click','li.yourclass', function(){
//do something with your element, which is "this"
});
The 'li.yourclass'
selector is dynamically tested at each click, so you don't need to test in the callback.
Upvotes: 2