html - getElementsByTagName inside a div class in Javascript -


i have div class multiple images in there not have specific id.

want when click on image, logo gets displayed @ different location.

<div class="gs-image-box"> <a href="http://www.car-logos.org/audi" target="_blank" class="gs-image gs-image-scalable"><img src="http://t0.gstatic.com/images?q=tbn:and9gctfbgu4equlbn9htr_1tqd_xhtayahqbhmyc31zhth_pnuga76wx4_asg" title="audi | audi car logos , audi car company logos worldwide" class="gs-image gs-image-scalable" style="width: 84px; height: 84px;"></a> </div> <div class="gs-image-box"> <a href="http://logok.org/audi-logo/" target="_blank" class="gs-image gs-image-scalable"><img src="http://t2.gstatic.com/images?q=tbn:and9gcrfmgt17fazj1obpw8ir7zuqr4gqmlm1owuu-rto3jjharur-p17fumcvi" title="audi logo | logok" class="gs-image gs-image-scalable" style="width: 112px; height: 84px;"></a> </div> 

therefore use getelementsbytagname, detailed code here http://fiddle.jshell.net/g1e25r6p/1/

however, works first tag [0] , not second 1 [1]

i'm stuck on days now, have idea, how or doing wrong?

first issues:

var badgeimg2 = imageresult[1].getelementsbytagname('img')[1]; 

should be

var badgeimg2 = imageresult[1].getelementsbytagname('img')[0]; 

second issue (in event listener code of badgeimg2):

var imgsrc = badgeimg.src; 

should be:

var imgsrc = badgeimg2.src; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -