Answers for "how to select element javascript"

0

How to select an Element in JavaScript

// Selecting an Element by id:
document.getElementById("elem-id");
// Selecting  Elements by class:
document.getElementsByClassName("elem-class");
// Selecting Elements by tag name: 
document.getElementsByTagName("div");
//  Selecting Elements by name:
document.getElementsByName("elem-name");
/* This method is like a jQuery selector 
( #elemId -> id, .elemClass -> class, h1 -> tag name) */
document.querySelector(".container"); // class
document.querySelector("#demo"); // id
document.querySelector("div"); // tag name
Posted by: Guest on May-28-2021

Code answers related to "how to select element javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language