light-dom-selector
v0.0.4
Published
Extra lightweight DOM selector helper
Downloads
1
Maintainers
Readme
light-dom-selector
Lightweight dom selector by simple symbols that outputs an
SelectorFn
instance.
Support Version IE 6+
Install
npm install light-dom-selector
// This module is only offered as a ES Module
import $ from "light-dom-selector";
// Common JS
const $ = require("light-dom-selector")
Select Dom
Note: if the dom is not exist, {element: undefined, constructor: Object}
this is the result.
getElementById
$("#app")
// => SelectorFn {element: Element, constructor: Object}
getElementsByClassName
$(".app")
// => SelectorFn {element: Element, constructor: Object}
querySelectorAll
$("*.app h1")
// => SelectorFn {element: Element, constructor: Object}
getElementsByName
$("~h1")
// => SelectorFn {element: Element, constructor: Object}
getElementsByTagName
$("@app")
// => SelectorFn {element: Element, constructor: Object}
Event
on
you can create event by on
method.
$("#app").on("click", function() {
/// event
});
$("#app").on("click mouseover", function() {
/// event
});
remove event by off
method.
function clickFn() {
console.log(this);
}
$("#app").on("click", clickFn); // addEventListener
$("#app").off("click", clickFn); // removeEventListener