You can manipulate the DOM using vanilla JS. You don't need jQuery or npm.
These methods work with a single element:
getElementById: Accepts anid.querySelector: Accepts a CSS selector.- The
styleproperty allows you to set CSS rules dynamically.
These methods work with multiple elements:
getElementsByClassName: Accepts aclass.getElementsByTagName: Accepts an HTML element's tag name.querySelectorAll: Accepts a CSS selector.
appendChildremoveChildinnerHTML
nodeValuesets or gets the text content of a text node.textContentsets or gets the text of the containing element.
firstChild: Get the first child element of a node.lastChild: Get the last child element of a node.parentNode: Access a parent node of an element.nextSibling: Get the element after the selected element.previousSibling: Get the element before the selected element.
getAttribute: Get an attribute, e.g.class,id,href, etc.setAttribute: Set a new attribute on an element, accepts the attribute and its name.hasAttribute: check if an attribute exists, accepts an attribute.removeAttribute: remove an attribute, accepts an attribute.id: Set or get theidof an element.className: Set or get theclassof an element.
document.addEventListener('click', function (event) {
if (event.target.id === 'clickity') {
// Someone clicked something.
}
}, false);document.addEventListener('DOMContentLoaded', function(event) {
// The DOM is ready!
});