Connecting Tech Pros Worldwide Help | Site Map

getElementsByTagName

  #1  
Old August 27th, 2008, 07:00 PM
Newbie
 
Join Date: Aug 2008
Posts: 17
Hi,

I have a set of elements by tag name eg. <img> I want to extract and also identify which one I have taken.

eg.

<a><img src="1.png"/></a>
<a><img src="2.png"/></a>

How do I get 1.png or 2.png .
  #2  
Old August 27th, 2008, 08:41 PM
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,102
Provided Answers: 1

re: getElementsByTagName


loop through the collection and check for the src-attribute ... do you have done anthing already? please post what you have so far ...

kind regards
  #3  
Old August 31st, 2008, 04:19 PM
Newbie
 
Join Date: Dec 2007
Posts: 3

re: getElementsByTagName


Expand|Select|Wrap|Line Numbers
  1. var objImages = document.getElementsByTagName('image');  for(var imgIndex =0; imgIndex<=objImages.length-1; imgIndex++)  {      var objImage = objImages[imgIndex];      //add your code here to handle objImage image object ;  }
  #4  
Old August 31st, 2008, 08:56 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,488
Provided Answers: 9

re: getElementsByTagName


you should use: document.getElementsByTagName('img') (<image> is not a valid tag name)
  #5  
Old September 2nd, 2008, 06:13 PM
Newbie
 
Join Date: Dec 2007
Posts: 3

re: getElementsByTagName


Quote:
Originally Posted by Dormilich
you should use: document.getElementsByTagName('img') (<image> is not a valid tag name)

:) yes I realise that. It was typo!!!. Obviously there is no such element with nodeName image.
  #6  
Old September 2nd, 2008, 09:44 PM
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,102
Provided Answers: 1

re: getElementsByTagName


not in html ... :) but in XUL for example it is ... certainly a typo and a good catch too to point that out to avoid confusion ... well done ... both of you ;))
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
getElementsByTagName returning empty set Ben answers 1 December 9th, 2006 06:55 PM
Calls to GetElementsByTagName affect performance of XML DOM Dima answers 7 November 12th, 2005 05:10 AM
How to retrieve XML sublevel, using GetElementsByTagName Andy answers 3 November 12th, 2005 04:44 AM
getElementsByTagName Michel Bany answers 23 July 23rd, 2005 10:28 PM
document.getElementsByTagName emulator for Netscape 4? 2obvious answers 6 July 20th, 2005 09:57 AM