toggle class to an element javascript
var menu = document.querySelector('.menu') // Using a class instead, see note below.
menu.classList.toggle('hidden-phone');// html <div class="parentElm" id="addActive"></div>
// js
function toggleClass(){
// get the properties of an element
var element = document.getElementById("addActive");
// check if the element have class list
if (element.classList) {
// add active class if true
element.classList.toggle("active");
} else {
var classes = element.className.split(" ");
var i = classes.indexOf("active");
}
}
Also in JavaScript:
- responsive grid using antd
- how to run a vue js hello world app in vue version 3
- bootstrap in javascript
- javascript return promise
- smtpjs attachment
- js fake await
- downgrade angular version in project
- javascript foreach in object
- get today's date javascript
- javascript filter and order
- post json in flutter
- oauth2 spring boot react google example
- how to set three js canvas width 100%
- how to create duplicate key array in javascript
- react enzyme
- how to change package name in react native
- javascript element by class
- get query param javascript
- how to validate the textbox using jquery
- javascript appendchild at index
- get top items from json object
- discord.js bad word filter
- javascript character ascii value modify
- JavaScript Operators