Similar to jQuery, DOMination provides a way to easily grab and edit html elements in the DOM. This is designed for beginning programmers using a semantic naming system to help understand what the methods do.
An overview of the methods are available below.
Given the following test code:
<div>
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class="subtitle1-caption">I am a caption</div>
</div>
We can grab specific elements, by calling the `$grab("htmlElement")``
divs = $grab('div')
// #=> DOMNodeCollection {htmlElements: Array(2)}
This will grab all div elements in the document and store them as a DOMNodeCollection Object. We can now refer to all div elements using divs
If you'd like to add the string "hello" to the inner html of a selected element,
divs.html('hello')
The resulting changes would be made
<div>hello // result of divs.html('hello')
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class="subtitle1-caption">hello</div>
</div>
If you wanted to remove the innerHTML to the elements
divs.empty('')
This will transform the document to remove all innerHTML to the selected element
<div>
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class="subtitle1-caption"></div>
</div>
To append/add on to the end of the innerHTML of the selected element
divs.append('hello')
This will transform the document and add HTML to the end of each element
<div>hello
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class="subtitle1-caption">I am a captionhello</div>
</div>
If you'd like to add className to the selected element
let = divs.addClass('addedClass')
This will add the classname to each HTML div element.
<div class="addedClass">
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class="subtitle1-caption addedClass"></div>
</div>
If you'd like to add className to the selected element
divs.removeClass('subtitle1-caption')
This will remove the classname to each HTML div element.
<div>
<h1>HELLO WORLD FOO BAR</h1>
<h2 class="subtitle1">I am a subtitle1</h2>
<div class=""></div>
</div>
If you'd like to find all children element to a selected element,
divs.children()
// #=> DOMNodeCollection {htmlElements: Array(3)}
This will return all children elements of div elements.
If you'd like to find a parent element to a selected element,
divs.parent()
// #-> DOMNodeCollection {htmlElements: Array(2)}
This will return the parent elements to the div elements.
Adding/removing event listeners
We can add event listeners to our target by,
divs.on('click',()=>console.log('hi'))
// #-> prints hi in console whenever a div element is clicked
We can remove event listeners to our target by,
divs.off('click')
// #-> prints hi will no longer show in console when div element is clicked
We can lastly make AJAX calls with DOMination. We do this by
$make.ajax()
// #-> will make a GET request