javascript - Can't change html attribute with external script -
i've got little problem javascript. i'm trying learn how change attribute on page using setattribute(name, value), , nothing happens.
this test site's html code:
<!doctype html> <html> <head> <meta charset=utf-8" /> <title>test</title> </head> <body> <div id="test" class="time"></div> <script src="js/script.js"></script> </body> </html> this javascript code:
if(document.getelementbyid("test").hasattribute("class")) { alert("got message"); var test = "test"; document.getelementbyid("test").setattribute("class", test); } it's simple, should work, alert pops up, , when check source of page, nothing changes. honest - tried several different approaches , nothing worked. must really, stupid can't find it.
change classes
document.getelementbyid("test").classname = test; add classes:
document.getelementbyid("test").classname += test;
Comments
Post a Comment