dommmDaniel uses vanilla JavaScript and the native DOM API to allow for manipulating the DOM, handling events, and making AJAX requests.
- Download dommmDaniel.js.
- In the header of your root html file, include the path to dommmDaniel.js in a
script
tag. - Start using dommmDaniel!
- Download the dommmDaniel folder.
- Place the dommmDaniel folder in your project directory.
- In the header of your root html file, include the path to dommmDaniel.js in a
script
tag. - Edit anything you'd like in main.js or dom_node_collection.js
- Run
webpack dommmDaniel/main.js dommmDaniel/dommmDaniel.js
- Start using your updated dommmDaniel!
$d(selector)
- if
selector
is a string, uses document.querySelectorAll(string) to select matching HTML elements and creates aDOMNodeCollection
out of them. - if
selector
is a HTML element, creates aDOMNodeCollection
instance that contains the matching HTML elements. - if
selector
is a function, it will be added as an event to the DOMContentLoaded event.
$d.ajax(options)
- makes an AJAX request.
- for any key/value pair in the optional
options
object argument, the corresponding key/value pair in the default options object is replaced. The final object is sent as data in the AJAX request.
After selecting elements and creating a DOMNodeCollection
with the core $d
function, you can use the following DOMNodeCollection.prototype
functions:
.html()
.html()
- returns the first node in the
DOMNodeCollection
.
- returns the first node in the
.html(string)
- replaces the innerHTML of each node in the
DOMNodeCollection
.
- replaces the innerHTML of each node in the
.empty()
- clears all HTML inside each node of the
DOMNodeCollection
.
.append(collection)
- adds the outerHTML of each node in the
collection
argument to the innerHTML of each node in theDOMNodeCollection
.
.attr()
.attr(attribute)
- returns the value of the specified
attribute
of the first node in theDOMNodeCollection
.
- returns the value of the specified
.attr(attribute, value)
- for each node in the
DOMNodeCollection
, the specifiedattribute
is set to the givenvalue
.
- for each node in the
.addClass(className)
- adds the given
class
to each node in theDOMNodeCollection
.
.removeClass(className)
- removes the given
class
from each node in theDOMNodeCollection
.
.children()
- returns a new instance of
DOMNodeCollection
containing the collective children of all nodes in theDOMNodeCollection
.
.parent()
- returns a new instance of
DOMNodeCollection
containing the collective parents of each node in theDOMNodeCollection
.
.find(selector)
- returns a new instance of
DOMNodeCollection
containing all descendants of the nodes that match theselector
.
.remove()
- removes all html of each node in the
DOMNodeCollection
.
.on(type, callback)
- adds an event listener of the given
type
to each node in theDOMNodeCollection
, which calls thecallback
when triggered.
.off(type, callback)
- removes an event listener of the given
type
andcallback
from each node in theDOMNodeCollection
.