• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

get all images in <tag id=myid>

hi experts,

I am trying to use the same Code Snippet  but insted of looking in the entire document, I only need to look  inside  <tag id=myid>,

reagrs,
for(var i=0; i< document.images.length; i++) {
	if(document.images[i].parentNode.tagName == "A")
          setupRollover(document.images[i]);
}

Open in new window

0
uk1900
Asked:
uk1900
2 Solutions
 
Tomarse111Commented:
Feed the following function your id and it will return all of the images within that parent:
<script>
function getImgs(id){
	var children = document.getElementById(id).getElementsByTagName('img');
}
</script>
 
 
//So for example, feeding getImgs id 'doc' returns a collection of 3 images
<body id="doc">
	<img id="a" src="" />
	<img id="b" src="" />
	<a href="" id="d">bob</a>
	<img id="c" src="" />
	<input type="button" onclick="getImgs('doc');">
</body>

Open in new window

0
 
Pawel WitkowskiSenior Javascript DeveloperCommented:

for(var i=0; i< document.getElementById('myid').length; i++) {
        if(document.getElementById('myid')[i].parentNode.tagName == "A")
          setupRollover(document.getElementById('myid')[i]);
}

Open in new window

0
 
uk1900Author Commented:
thx man
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now