I have this code:
<ul>
<li class="foo" onclick="alert('Hello')">a</li>
<li class="foo" onclick="alert('Hello')">b</li>
<li class="foo" onclick="alert('Hello')">c</li>
</ul>
I want to prevent the default action alert()
when click in <li>
with text "a", and I use this code:
$(document).on('click','.foo', function(){
if ($(this).text()=='a')
return false;
});
But this doesnt work: http://jsfiddle.net/Trk6W/10/
Is there a solution only modifying the javascript?
Updated: I dont wanna remove the attribute onclick
because the values of li
can change