$("div#buttonContainer ul li").live("click",function(){
if($(this).hasClass('selected')){
alert('selected');
}
});
<div id="buttonContainer">
<ul>
<li class="selected"></li>
<li></li>
<li></li>
</ul>
</div>
I have the click handler that applies to all the li tags, but I want specific function to execute when the li has the selected class. The javascript above pops up the alert on any li clicked. I’m not sure what I’m doing wrong, perhaps I’m not targeting the specific li properly.
EDIT:
I must use jquery 1.3 techniques as I can’t upgrade.
As the other posters have responded the simple case is working in jsFiddle, I am going to assume that in your actual app something has changed the this context. So this solution will remove this from the picture and use the target of the click with live so it will still work in jQuery 1.3