How to fire event if CSS class is changed using jQuery ?
Given an HTML document with heading and button, jQuery should fire an event when the CSS class of the button changes.
Approach: In jQuery, there is no provision to trigger an event on class change. An alternative method is to manually raise an event when you programmatically change the class using the trigger() function. The trigger() function will raise an event whenever the class of the button is changed.
Initially the page looked like the following image.
On clicking the button, an alert message pops up indicating that the listener was fired and the CSS class of the button has changed.
After closing the popup, the button’s CSS class changed (notice the green background color and white text).
Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML course.