madsovenielsen Posted August 11, 2009 Share Posted August 11, 2009 Hey. i just want to know if this is a 100% valid JavaScript. function changeImage() {newImage = "url(test2.png)";document.getElementById('image').style.backgroundImage = newImage;} Its Working fine. Is it the simplest way of doing it ?/mads Link to comment Share on other sites More sharing options...
Ingolme Posted August 11, 2009 Share Posted August 11, 2009 Hey. i just want to know if this is a 100% valid JavaScript.function changeImage() {newImage = "url(test2.png)";document.getElementById('image').style.backgroundImage = newImage;} Its Working fine. Is it the simplest way of doing it ?/mads It is completely valid.You could make your function more flexible by allowing the programmer to set the new image URL in the function parameter:function changeImage(url) { document.getElementById('image').style.backgroundImage = "url(" + url + ")";} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.