jQuery addClass example
Change class name on click in jQuery
by salt
HTML
<a href="#">Change color</a>
JavaScript
// find elements
var mutationObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation);
});
});
// Starts listening for changes in the root HTML element of the page.
mutationObserver.observe(document.documentElement, {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
//$.extend({},oldJSON,serverData);
var insertionListener = function(event) {
// Making sure that this is the animation we want.
if (event.animationName === "nodeInserted") {
console.log("Node has been inserted: " + event.target);
}
}
document.addEventListener("animationstart", insertionListener, false); // standard + firefox
document.addEventListener("MSAnimationStart", insertionListener, false); // IE
document.addEventListener("webkitAnimationStart", insertionListener, false); // Chrome + Safari
HTMLAnchorElement.prototype.update = function(){
alert($(this).data("data"))
}
var button = $("a")
button.data("data",1)
// handle click and add class
button.on("click", function(){
button.data("data",99)
button.addClass("aaa")
this.update()
})