- Allow programmer to listen for attribute and child node of DOM element event.
- JQuery attribute event.
- JQuery child node of DOM element event.
<script src="https://cdn.rawgit.com/Chomtana/EventX-css-event/f96312db/dist/eventx-css.js"></script>
npm install eventx-css-event
Name | Description | Example |
---|---|---|
stylechange |
Listen to inline and media screen style change | Click |
stylechange:<...> |
Listen to inline and media screen style change (Only style <...>) | Click |
inlinestylechange |
Listen to inline style change | Click |
inlinestylechange:<...> |
Listen to inline style change (Only style <...>) | Click |
mediastylechange |
Listen to media style change | |
mediastylechange:<...> |
Listen to media style change (Only style <...>) |
I want to alert "Div Added" when div was added as a child node of #ex.
const target = $("#ex")[0];
var config = { childList: true };
const ob = new MutationObserver(mutationsList => {
for (var mutation of mutationsList) {
if (mutation.target == target && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(node=>{
if (node.nodeName.toUpperCase() == "DIV") {
alert("Div Added");
}
}
}
}
});
var config = { attributes: true, attributeOldValue: true, attributeFilter: ["style"]};
ob.observe(target[0],config);
Note: Above example require JQuery
$("#ex").on("inlinestylechange",function(e) {
if (e.oldStyleValue && e.newStyleValue) alert("Style "+e.styleName+" changed from "+e.oldStyleValue+" to "+e.newStyleValue);
else if (!e.oldStyleValue && e.newStyleValue) alert("Style "+e.styleName+" added with value "+e.newStyleValue);
else if (e.oldStyleValue && !e.newStyleValue) alert("Style "+e.styleName+" removed with old value "+e.oldStyleValue);
});
Note: Above example require JQuery
- First and final block obviously shorter.
- Closer to english language.
- Remember easier.
evx.on(document.getElementById("ex"),"inlinestylechange",function(e) {
if (e.oldStyleValue && e.newStyleValue) alert("Style "+e.styleName+" changed from "+e.oldStyleValue+" to "+e.newStyleValue);
else if (!e.oldStyleValue && e.newStyleValue) alert("Style "+e.styleName+" added with value "+e.newStyleValue);
else if (e.oldStyleValue && !e.newStyleValue) alert("Style "+e.styleName+" removed with old value "+e.oldStyleValue);
});
Yeah, still simple and easy.
You can find list of event name here
$("#ex").on("<event name>",function(e) { console.log(e,this); ... });
evx.on(<target HTMLElement>,"<event name>",function(e) { console.log(e,this); ... });
- View all JQuery coding style at http://api.jquery.com/on/
- e is a Edited MutationRecord object
- this = target element (Warning: not working if you use arrow function)
- For more information about Edited MutationRecord run console.log(e) in event handler or read here
$("#ex").off("<event name>");
evx.off(<target HTMLElement>,"<event name>",[handler (Optional)])
- View all JQuery coding style at http://api.jquery.com/off/
evx.renameEvent("<event name>","<newname>")
Property Name | Type | Description |
---|---|---|
target | HTMLElement | Target element which style has been changed |
styleName | String | Name of style that has been changed |
oldStyleValue | String | Value of that style before changed |
newStyleValue | String | Value of that style after changed |
changetype | String | "inline" if inline change or "media" if media change |
Released under the MIT License Copyright © 2018 Chomtana