I'm trying to add a class to a div in pure JS once a link is clicked (In this case, the link has id #switchlogin
). When I console.log my element, I am able to click through the object and see that it currently has two names in its classList
. However, when I console.log element.classList
, I receive an "undefined". I am unsure why I'm receiving undefined, and why I cannot add my new class name.
The issue is recreated here: https://jsfiddle.net/swf5zc74/
Here is a portion of my HTML:
<div class="sign_in modal">
<h1>Get Started!</h1>
<form action="" method="get">
<input type="text" name="fname" placeholder="Name" required>
<input type="text" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Submit" class="submit">
</form>
<h3><a href="#" id="switchLogin">Been Here Before?</a></h3>
</div>
My JS:
var body = document.getElementsByTagName('body'),
signIn = document.getElementsByClassName('sign_in modal'),
logIn = document.getElementsByClassName('log_in'),
switchLogIn = document.getElementById('switchLogin'),
switchSignIn = document.getElementById('switchSignin'),
link = document.querySelector('a');
link.addEventListener("click", function(e){
if ((e.target || e.srcElement).id == 'switchLogin'){
console.log(signIn);
console.log(signIn.classList);
signIn.classList += ' slideOut';
}else{
console.log("nope");
}
})