toggle.mjs
TLDR
This file provides a function toggleOnClick
which adds or removes a specified CSS class to a target element when a specified element is clicked.
Methods
toggleOnClick
This method takes three parameters: el
, target
, and className
. It selects an element using the el
parameter, and a target element using the target
parameter. When the selected element is clicked, it toggles the specified CSS class (className
) on the target element.
Classes
/**
Mobile animation list
*/
const toggleOnClick = (el, target, className) => {
const element = document.querySelector(el)
const targetEl = document.querySelector(target)
element.addEventListener('click', e => {
targetEl.classList.toggle(className)
})
}
export default toggleOnClick