extrajs-dom
Javascript extensions to DOM.
DOM code is kinda spaghetti-like. Use this package to streamline your code and keep the control flow sensible.
Install
$ npm install extrajs-dom
Example
traditional DOM methods:
{ let link = document linkclassList link link link linkrel = 'author' linkhref = url linktextContent = text return link}
extrajs-dom methods:
const xjs = const createMyLink = document rel'author' hrefurl node // returns the modified Node (originally passed to constructor)
Features
- Method chaining
xjs.Node#empty()
removes all childrenxjs.Node#trimInner()
removes all empty and whitespace-only Text node descendantsxjs.Node#run()
executes a custom function for any unsupported features you might needxjs.Node#select()
executes a custom function based on a conditionxjs.Element#attr()
sets/removes multiple attributes in one step; taking object and function argumentsxjs.Element#{addClass,removeClass,replaceClassString}()
for better[class]
attribute manipulationxjs.{Document,DocumentFragment}#innerHTML()
gets what you would expect- Populate
<ol>
,<ul>
,<tbody>
, and<tr>
as lists of data