Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get element by class name

let elementsArray = document.getElementsByClassName("className");
// OR
let element = document.querySelector(".className");
Comment

javascript get element by class

var elements = document.querySelector(".class");
Comment

get element by class

var elements = document.getElementsByClassName(names); // or:
var elements = rootElement.getElementsByClassName(names);
Comment

get element by class

var x = document.getElementsByClassName("example");
var i;
for (i = 0; i < x.length; i++) {
  x[i].style.backgroundColor = "red";
}
Comment

Getting Elements by Class Name

let blueThings = document.getElementsByClassName('blue');

console.log(blueThings);                        // The HTMLCollection
console.log(blueThings[0]);                     // The first element with class="blue" in the document
console.log(blueThings.length);                 // The number of elements with class="blue" found
console.log(blueThings.item(2));                // The element at index 2 in the collection
console.log(blueThings.namedItem('specific'));  // The element with both class="blue" and id="specific"
Comment

javascript get element by class

const whiteBoxes = document.getElementsByClassName("box-white")
Comment

how to get element by class name javascript

document.getElementsByClassName("legend").style.display="none";
Comment

get element by class name

var y = document.getElementsByClassName('foo');
var aNode = y[0];
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript difference between two dates 
Javascript :: window resize event javascript 
Javascript :: length of dict js 
Javascript :: javascript after time call function 
Javascript :: settimeout en javascript 
Javascript :: is string javascript 
Javascript :: add id jquery 
Javascript :: number to char js 
Javascript :: ajax get request 
Javascript :: js parse string to html elemen 
Javascript :: jquery ajax form submit 
Javascript :: js remove falsey values from array 
Javascript :: list of currencies with code js 
Javascript :: install latest npm for react 
Javascript :: remove apex chart toolbar 
Javascript :: javascript wait for document load 
Javascript :: Uncaught TypeError: $(...).select2 is not a function 
Javascript :: javascript audio stop 
Javascript :: execute javascript on page load jquery 
Javascript :: create new react project 
Javascript :: integer to roman javascript 
Javascript :: how to run a vue js hello world app in vue version 3 
Javascript :: automatically scroll to bottom of page 
Javascript :: npx for windows 
Javascript :: jquery tag name 
Javascript :: change format date javascript 
Javascript :: how #region javascript 
Javascript :: $(...).autocomplete is not a function 
Javascript :: react native rotate image 
Javascript :: run react native app in production mode 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =