+ 1
What is the benefit of using setAttribute and getAttribute? Even though we can change it directly from html
2 Respuestas
+ 3
Yes, but with JS you can make changes dynamically ( ie. you'll don't go behind every user to edit their html source code regards of their action? )...
+ 2
<body bgcolor=blue>
<button onclick="changeColor()">Click Me</button>
function changeColor() {
document.body.setAttribute("bgcolor", "red") ;
} // if you click that button, body will have a different background color.