I have a modal window. Inside it there is a table with id WebPartWPQ2 which will have three different classes in three different states. The classes being ms-applyfiltersinactive, ms-applyfiltersactive and ms-applyfiltershoverover. Initially, when the modal window pops up, the table will have ms-applyfiltersinactive class. Only on change of an option in the select box inside it, the class of the table changes to ms-applyfiltersactive and then on mouse hover the class changes to ms-applyfiltershoverover. On closing the window, the class of the table resets to ms-applyfiltersinactive.
The requirement is that I need to have a click event on the table only when it is active i.e. has a class ms-applyfiltersactive or ms-applyfiltershoverover.
I am using
$(document).on("click","#WebPartWPQ2 .ms-applyfiltersactive, #WebPartWPQ2 .ms-applyfiltershoverover", function(){
alert("Clicked");
});
This fails to attach the click event to the table. This might be because the class of the table then is ms-applyfiltersinactive.
If I use the following code
$(document).on("click","#WebPartWPQ2 table[class*='ms-applyfilter']", function(){
alert("Clicked again");
});
the event is fired in all the three cases, which I do not want.
I have tried to filter out the selectors using hasClass and is events.
$(document).on("click","#WebPartWPQ2 table[class*='ms-applyfilter']", function(){
alert($(this).is("table.ms-applyfiltersactive"));
});
But this returns the same boolean when the table has any class.
Please help me out with this.