html - Javascript - Change element's src in specified element -


in html have lot od divs names(yes, names, not ids) respectively p001, p002, p003... this:

<div id="pole" name="p001"><img src=""></div> <div id="pole" name="p002"><img src=""></div> <div id="pole" name="p003"><img src=""></div> 

etc...

in javascript have defined variable called 'pos' contains number, now: "284" , function should change img src "player.png". tried 2 ways , none of these work:

document.getelementsbyname('p'+pos).innerhtml='<img src="player.png">'; 

and

document.getelementsbyname('p'+pos).getelementsbytagname("img").src="player.png"; 

how change img src in specified div?

getelementsbyname returns list of elements, not single element, try:

document.getelementsbyname('p'+pos)[0].     getelementsbytagname("img")[0].src="player.png"; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -