Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

addclass js vanilla

  element.classList.add('className');
Comment

vanilla javascript add class

document.addEventListener("DOMContentLoaded", function() {
  var faqContainers = document.getElementsByClassName('faq-container')
  var faqToggle = document.getElementsByTagName('body')[0]
  for (var i = 0; i < faqContainers.length; i++) {

    faqContainers[i].addEventListener('click', function() {
      if (faqToggle.classList.contains('faq-display')) {
        faqToggle.classList.remove('faq-display')
      } else {
        faqToggle.classList.add('faq-display')
      }
    })
  }
})
Comment

javascript add class to element

const element = document.querySelector('CSS_SELECTOR')

element.classList.add('class-1') // add class-1
element.classList.remove('class-1') // remove class-1
element.classList.toggle('class-1') // add class-1 if the element does not contains the class, remove if not.
Comment

how to add a class to an element in javascript

// This is to add a class to any html element after you store it
// in the element variable 

element.classList.add("my-class-name");

// This is to remove a class from the element

element.classlist.remove("my-class-name");


Comment

js add class to html

const root = document.getElementsByTagName('html')[0]
root.classList.add('hide-scrollbar')
Comment

How to add a class to html element js

element.classList.add("my-class");
Comment

add class to new element js

    const exampleElement = document.createElement('div');

    exampleElement.classList.add("exampleClass");

	const container = document.getElementById('container1');
    container.appendChild(exampleElement);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript onsubmit 
Javascript :: remove element from array in js 
Javascript :: npm http status codes 
Javascript :: how to find the smallest two numbers in an array javascript 
Javascript :: change key in array of objects javascript 
Javascript :: jquery find previous element with class 
Javascript :: aos animation angular 
Javascript :: get $_get in javascript 
Javascript :: jsp include html 
Javascript :: js input type range get value while sliding 
Javascript :: how to generate unique id in node js 
Javascript :: remove brackets from array javascript 
Javascript :: nested loops javascript 
Javascript :: find the index of an object in an array 
Javascript :: how to send a message discord.js 
Javascript :: JS ignoring accents 
Javascript :: function js format money 
Javascript :: convert time string in javascript 
Javascript :: javascript window size 
Javascript :: laravel jquery csrf 
Javascript :: js camalcase 
Javascript :: angular add a new line from component 
Javascript :: ngmodel angular 
Javascript :: how to hide button in react 
Javascript :: chrome.tabs.query( 
Javascript :: when a form is subbmited jquery 
Javascript :: jquery set inner text 
Javascript :: remove duplicate json object from array javascript 
Javascript :: if back react 
Javascript :: print page in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =