Identify Image

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Identify Image

Post by pcoder »

Is it possible to identify image from ID/Name attributes? I tried, but I couldn't.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Identify Image

Post by kaszu »

Please clarify what you mean by "identify"
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Identify Image

Post by pcoder »

Ok,
I have an ID/Name attribute of an element. And I need to identify whether it's image or not.
In case of other input elements, I can identify by the type.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Identify Image

Post by jackpf »

Hmm...you could try tagName to see if it's "img".
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Identify Image

Post by pcoder »

Ok, for example, I have an image element:

Code: Select all

 
<img src="a.gif" id="image">
 
In javascript, I have only the ID attribute, ie. image.
But, How could I use the tagName to identify image from ID.
Can you give a line of code for this.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Identify Image

Post by jackpf »

How about

Code: Select all

if(document.getElementById('image').tagName == 'img')// it's an image
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Identify Image

Post by pcoder »

Thanks jackpf, worked!!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Identify Image

Post by jackpf »

Cool :)
Post Reply