JavaScript get element code example
Example 1: javascript get element by id
var element = document.getElementById("YourElementId");
Example 2: get element in js
var elem1 = document.getElementById("demo-id");
var elem2 = document.getElementsByClassName("demo-class");
var elem3 = document.getElementsByName("demo-name");
var elem4 = document.getElementsByTagName("p");
var elem1 = document.querySelector("#demo-id");
var elem2 = document.querySelectorAll(".demo-class");
var elem3 = document.querySelectorAll('[name="demo-name"]');
var elem4 = document.querySelectorAll("p");
Example 3: get element by id in javascript
document.getElementById("YourElementId");
Example 4: get element in javascript
document.getElementById("elem-id");
document.getElementsByClassName("elem-class");
document.getElementsByTagName("div");
document.getElementsByName("elem-name");
document.querySelector("h1");
Example 5: get all a tags javascript
document.anchors