DOM Control

Selecting

  • Can put any selector in string for jsss

document.getElementById().getElementByTagname("input")
document.querySelector('.class')//return first
document.querySelectorAll('.class')//return NodeList(not array so no forEach?)

Modifying Elements

Can retrieve or set any attribute

document.getElementById("myname").type="radio"
document.getElementById("myname").value="Jorge"
elem.style.display = 'none';

Creating Elements

const container = document.createElement("div");
container.setAttribute("id", containerId);
document.body.appendChild(container);

Deleting Elements

const container = document.getElementById(containerId);
if (container === null) return;
container.parentNode.removeChild(container);

Other DOM Stuff

URL

Scrolling

Options is a dict of

  • top i,e y-coord

  • left i.e x-coord

  • behavior = smooth| instant| auto

Get Forms

JQuery

Last updated