I have a situation like this:
HTML
<span class="element e1" id="FirstElement" onclick="Javascript:alert(this.id)">
<span class="element e2" id="SecondElement" onclick="Javascript:alert(this.id)"> ELEMENT </span>
</span>
<button class="addButton"> ADD CLASS </button>
JAVASCRIPT:
$(document).ready(function() {
$('span.element.anotherClass').click(function(e) {
alert("ANOTHER ACTION");
return false; // I tried also preventDefault() but not working
});
$('.addButton').click(function(e){
$('span.element').addClass(" anotherClass");
});
});
Note the two span elements have a onclick action. I want that after adding a class to these elements by clicking on the button, they stop doing the old onclick actions and start doing the new action ( = show the "ANOTHER ACTION" alert).
You can try the code above in this Fiddle.
Hope someone will help me with this problem I can't figure. Thanks