0
Javascript no added css class
// Css class add hoy na please help me //Code check please //Problem thank solution korean please var name = prompt('your name'); var name2 = ('shorif shuvo'); var names = (name + '<br>'); var password1 = parseInt(prompt("your password")); var password2 = parseInt(prompt('confirm password')); if (password1 === password2) { for (var i = 0; i < 10; i++) { document.write(names); } } else { document.write('Are you bad boy'); } var bg = document.getElementsById("bg"); if (name2 == name) { bg.classList.add("bd"); } /* class not add please help me */
2 Respuestas
+ 2
class is added, but document.write open a new document, so css are deleted...
you must either assign document.body.innerHTML, or dynamically document.write css (inside <style> tag) :
document.body.innerHTML += "appended to body content";
0
CSS CODE
body {
font-size: 30px;
font-weight: 500;
}
.bg{
background-image: url("../images/img-profile.jpg");
color: white;
}