-2
I tested and the result was the same using the property className
and the method classList.toggle
:
- So what is the advantage and disadvantage of using?
Using the className
:
var btnSignin = document.querySelector("#signin");
var btnSignup = document.querySelector("#signup");
var body = document.querySelector("body");
btnSignin.addEventListener("click", function () {
body.className = "sign-in-js";
});
btnSignup.addEventListener("click", function () {
body.className = "sign-up-js";
});
Using the classList.toggle()
:
var btnSignin = document.querySelector("#signin");
var btnSignup = document.querySelector("#signup");
var body = document.querySelector("body");
btnSignin.addEventListener("click", function () {
body.classList.toggle("sign-up-js");
});
btnSignup.addEventListener("click", function () {
body.classList.toggle("sign-up-js");
});
View documentation of both classname and classList.
– Giovane