JQuery on class delete event
Well, I have something like this:
HTML:
<div id="main" class="underline" >Hello</div>
JavaScript:
$('div').live('click', function(){
$(this).toggleClass("underline");
});
I need to run some function for the event when the div class was deleted, and I do not have any rights to edit functions that add / remove the class from the div.
How can I catch this event when a class is deleted?
The 'click' event was used only as an example, so the class can be removed not only by clicking
NOTE: live()Deprecated. Try using the latest version of jquery
$('body').on('click', 'div#main', function(){
$(this).toggleClass("underline");
// to check the class presence
if($(this).hasClass('underline'))
alert('no class');
else
alert('has underline');
});
or use delegate ()
$('body').delegate('div#main', 'click', function(){
$(this).toggleClass("underline");
});