classname toggle js
/* var or const followed by its name */.getElementById(/* HTML element ID */);
/* var or const's name */.classList.toggle(/* Name of CSS class */);
// I hope this helps! document.getElementById('myButton').onclick = function() {
this.classList.toggle('active');
}var menu = document.querySelector('.menu') // Using a class instead, see note below.
menu.classList.toggle('hidden-phone');document.getElementById('myButton').onclick = function() {
var className = ' ' + myButton.className + ' ';
if ( ~className.indexOf(' active ') ) {
this.className = className.replace(' active ', ' ');
} else {
this.className += ' active';
}
}
Also in JavaScript:
- jquery is not defined rails
- video recorder using webrtc and javascript
- how to make a rectangle in matter.js
- javascript object keys foreach
- php generate random string fixed length
- jstl expects equals
- convert date time to string javascript
- see if discord message is in dm discord.js
- javascript append array to array
- react eslint prettier
- Javascript looping through table
- random array javascript
- how to get the square root in js
- jQuery change select value
- javascript detect square number
- sequelize get data
- nodejs aws s3 bucket delete item
- javascript fisher yates shuffle mdn
- handleClickoutside custom hook react
- date masking javascript to not allow /
- how do i listen to a keypress in javascript
- adding event listener keypress event in javascript
- react font awesome
- node js store values in file