+ 1

What is the benefit of using setAttribute and getAttribute? Even though we can change it directly from html

1st Feb 2017, 10:45 AM
Anita Sharma
Anita Sharma - avatar
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? )...
1st Feb 2017, 11:09 AM
visph
visph - avatar
+ 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.
1st Feb 2017, 10:57 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar