Why isn't my param working?
function myFunc(e){
e = e || 'add' || 'remove';
document.body.classList.e('hide');
}
myFunc(remove);
myFunc(add);
if was trying to this
function spinner(e){
let $spinner = document.querySelector('.isolador_spinner');
if ( e === 'remove' ){
$spinner.classList.remove('hideSpinner');
} else if ( e === 'add' ) {
$spinner.classList.add('hideSpinner');
} else {
console.log('e was not defined');
}
}
It claims e is not a function
To access an object property via an indirect variable, use bracket notation :
document.body.classList[e]('hide');
I'd also suggest using a name other than e
for your parameter. In JavaScript, a function parameter named e
conventionally means e
is an Event . Calling it action
might be a better choice.
The code you added in your edit also has a problem:
myFunc(remove); // wrong - remove is not a variable
myFunc('remove'); // correct
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.