DOMesticate is a JavaScript library used for DOM manipulation. The library is used for creating/removing DOM elements, add/remove/toggle elements classes, traverse elements, create/remove listeners, and make ajax reqs.
$domesticate()
is the function we use to wrap HTML elements, to be able to use the libraries functions.
$domesticate can take string and function arguments. If the argument is a string it will query the DOM looking for string CSS selector passed in. If the argument is a function, it will queue it up to the list of callbacks to invoke for once the DOM is loaded.
html()
will set the innerHTML of this
to argument - if no argument is supplied it will return this
's current innerHTML.
empty()
will reset the innerHTML of this
.
append()
is used to add HTMLElements to the DOM.
attr()
is used as a getter or setter (depending on arguments passed in) of attributes on a DOM element.
These two methods serve to add a class to the list of classes, or remove all classes.
remove()
will remove the element from the DOM entirely.
children()
will return a node collection of all inner HTMLElements
parent()
will return the parent of a given node element. If multiple elements are selected, parents of all elements will be returned.
find()
will query the DOM, searching for selector passed in as argument.
on()
takes an event type (ex: 'click'
) as well as a callback to be invoked on event firing.
off()
takes two optional arguments (eventType and callback), to remove callback associated with that eventType. If no argument is supplied, all events will be toggled off for given node.
$domesticate.ajax()
takes an options object as argument, and will merge that with the pre-set defaults. This includes the request type "GET".