Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get element in js

//<div id="demo-id"></div>
var elem1 = document.getElementById("demo-id");
//<div class="demo-class"></div>
var elem2 = document.getElementsByClassName("demo-class");
//<div name="demo-name"></div>
var elem3 = document.getElementsByName("demo-name");
//<p>Some text</p>
var elem4 = document.getElementsByTagName("p");

//<div id="demo-id"></div>
var elem1 = document.querySelector("#demo-id");
//<div class="demo-class"></div>
var elem2 = document.querySelectorAll(".demo-class");
//<div name="demo-name"></div>
var elem3 = document.querySelectorAll('[name="demo-name"]');
//<p>Some text</p>
var elem4 = document.querySelectorAll("p");
Comment

get 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("h1");
Comment

PREVIOUS NEXT
Code Example
Javascript :: handlechange in react 
Javascript :: jquery number counter 
Javascript :: javascript split string by multiple characters 
Javascript :: react native inline style 
Javascript :: npm fs 
Javascript :: js encode url 
Javascript :: How to get the background image URL of an element using jQuery 
Javascript :: react native grid view 
Javascript :: completely remove duplicate element from the array 
Javascript :: react dynamic load script 
Javascript :: ace editor set theme 
Javascript :: how to merge two object arrays in javascript 
Javascript :: react-stripe-checkout 
Javascript :: pass multi variable in ajax 
Javascript :: sentry ignoreerrors 
Javascript :: full text search all string fields in the index mongodb 
Javascript :: how to check request method was a get 
Javascript :: dynamic imports js 
Javascript :: change the position of div using javascript 
Javascript :: check nbt on item minecraft 
Javascript :: JS two numbers in array whose sum equals a given number 
Javascript :: js loop away backward 
Javascript :: how to check if user has installed pwa 
Javascript :: auto import vscode not working 
Javascript :: flatten an array javascript 
Javascript :: axios error message 
Javascript :: jquery console log 
Javascript :: remove element from array 
Javascript :: chart.js how to aligns legend in the chart 
Javascript :: connect ECONNREFUSED 127.0.0.1:80 nuxt config 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =