Question:
Change all images in HTML document using Javascript?
metaltune455
2012-06-23 23:56:42 UTC
So basically, I have a button. And onclick, the button would run the following script:



My goal is to "reset" the images because I have a "onmouseover" thing on the images. So when I click this button, I want it to set the images back to "Blank.jpg" which is just a white, blank picture. However, when I click the button, nothing happens.... can someone explain why? or offer me another alternative script?


P.S. The code is suppose to be ("img").src = 'blank.jpg' idk why they put '...' there instead of the '='
Three answers:
2012-06-24 02:11:44 UTC
Shape wise, depending on time and place, shields could be round, oval, square, rectangular, triangular or scalloped. Sometimes they took on the form of kites, flatirons or figures-of-eight, or had rounded tops on a rectangular base with perhaps an eyehole inserted. The shield was held by a central grip or by straps which went over or around the user's arm
David
2012-06-24 05:54:21 UTC
It doesn't work because .getElementsByTagName() returns a node list, and collection of nodes. It's not like a regular array so you can't just treat it like that. See here for more information about nodeList -- https://developer.mozilla.org/En/DOM/NodeList



Now to get around this is quite easy. I'll change the node list into an array, iterate over it, and change the src of each element returned by it: http://jsfiddle.net/KpMN8/
Jerald Lopez
2012-06-24 01:46:01 UTC
function AllImageReset( ) {

var images = document.getElementByTagName("img");

for( var x in images ) {

images[x].setAttribute( 'src', 'blank.jpg' );

}

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...