Toggle Class of
Another Element
<!-- Trigger -->
<button>Do Stuff</button>
<!-- Target -->
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus doloremque voluptatum error quae minima voluptates vero, harum iste, recusandae odit beatae libero vitae. Iste sequi voluptatibus modi nesciunt laborum animi.</p>
// class to toggle
.do-this {
background: coral;
}
// variables
const trigger;
const target;
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// do this to target element
// toggle class name
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// Arguements: ( typeOfEvent, function )
trigger.addEventListener();
// do this to target element
// toggle class name
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// Arguements: ( typeOfEvent, function )
trigger.addEventListener( 'click');
// do this to target element
// toggle class name
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// Arguements: ( typeOfEvent, function )
trigger.addEventListener( 'click' , () => {} );
// do this to target element
// toggle class name
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// Arguements: ( typeOfEvent, function )
trigger.addEventListener( 'click' , () => {
// do this to target element
// toggle class name
});
// variables
const trigger = document.querySelector('button');
const target = document.querySelector('p');
// on click
// Arguements: ( typeOfEvent, function )
trigger.addEventListener( 'click' , () => {
// do this to target element
// toggle class name
target.classList.toggle('do-this');
});
UI Patterns
By Manikoth
UI Patterns
- 1,033