SoFunction
Updated on 2025-03-10

Find the js code of img's src address under div

Purpose: Find the src of img under div
html:
<div ><img src="" /></div>
<div ><img src="" /></div>
.
.
<div ><img src="" /></div>

My error code:
initImage(); 
loadImage(); 
function initImage() {
for(var i=1;i<13;i++) {
imageId[i]=("image"+i);
}
}
function loadImage() {
for(var j=1;j<13;j++){
imageList[j]=imageId[j].getElementsByTagName("img")[0];
if(imageId[j].src=="images/")
imageId[j].src="images/"+j+".gif";
else..........
}
}
Code to solve the problem
Copy the codeThe code is as follows:

<div >
<div><img src="" /></div>
<div><img src="" /></div>
</div>
<script>
function imglist(obj)
{
var imglist=(obj).getElementsByTagName('IMG')
for (i=0;i<;i++ )
{
if(imglist[i].("",0)!=-1){imglist[i].src="imgage/"+i+".gif";}
alert(imglist[i].src) //The test is successful
}
}
</script>
<input onclick="imglist('listimg')" value="test" type="button">