dom-conform

Resolve and find element class names

Usage no npm install needed!

<script type="module">
  import domConform from 'https://cdn.skypack.dev/dom-conform';
</script>

README

dom-conform

Resolve and find element class names

Concept

//Add "hello" to the element class list.
conform(element, "hello", true);

//Remove "hello" from the element class list.
conform(element, "hello", false);

//Determine whether the element class list contains "hello"
conform(element, "hello");
//Return the first child of element conforming to "world"
conform.find(element, "world");

//Run the callback function on each child of element conforming to "world"
conform.find(element, "world", callback);
//Return the first parent of element conforming to "world"
conform.closest(element, "world");

Examples

var submit = function() {
    //Mark the form as "invalid"
    conform(form, "invalid", true);
}
var layout = function() {
    //Run the specified function on conforming childs
    conform.find(element, "aspect-fill", function(child){
        //Calculate ratio and update child geometric style properties.
    });
}
var menuClickHandler = function(event) {
    //Get the menu item of the clicked target
    var item = conform.closest(event.target, "menu-item");
}