Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript add class to all child elements

// Add class 'hide' to every child div on 1st child lvl 
var el = document.getElementById('your-element-id');
var classList = 'classList' in el;
for (var i = 0; i < el.children.length; i++) {
  var child = el.children[i];
  if (child.tagName == 'DIV') {
    if (classList) {      
        child.classList.add('hide');                                  
    } else {
      child.className += ' hide'
    }}}  
Comment

PREVIOUS NEXT
Code Example
Javascript :: get epoch timestamp js 
Javascript :: js delete dot 
Javascript :: javascript split array into chunks of 
Javascript :: dotnet core ajax post of an ojject site:stackoverflow.com 
Javascript :: jquery get 
Javascript :: jquery fadein 
Javascript :: set background image in material ui 
Javascript :: hide / show jquery 
Javascript :: set cookie javascript 
Javascript :: valid json return null on json_decode 
Javascript :: query params in next js 
Javascript :: js console log without spaces 
Javascript :: chrome inspector console tips 
Javascript :: jquery remove closest 
Javascript :: javascript context arc set color 
Javascript :: external linking of JavaScript in html 
Javascript :: Function in JavaScript that can be called only once 
Javascript :: generate random otp in node js 
Javascript :: js array for in vs for of 
Javascript :: generate random date in a range 
Javascript :: react native image disable fade in onload 
Javascript :: add dev dependency yarn 
Javascript :: find the missing value in an integer array javascript 
Javascript :: mongodb count conditional array items 
Javascript :: nextjs absolute import 
Javascript :: javascript separate words by capital letter 
Javascript :: change elements class javascript 
Javascript :: in array in js 
Javascript :: search filter in react js using api function components 
Javascript :: javascript radio button change event 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =