Page 1 of 1
Identify Image
Posted: Sun Sep 06, 2009 12:43 am
by pcoder
Is it possible to identify image from ID/Name attributes? I tried, but I couldn't.
Re: Identify Image
Posted: Sun Sep 06, 2009 4:17 am
by kaszu
Please clarify what you mean by "identify"
Re: Identify Image
Posted: Sun Sep 06, 2009 5:40 am
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.
Re: Identify Image
Posted: Sun Sep 06, 2009 6:03 am
by jackpf
Hmm...you could try tagName to see if it's "img".
Re: Identify Image
Posted: Sun Sep 06, 2009 6:24 am
by pcoder
Ok, for example, I have an image element:
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.
Re: Identify Image
Posted: Sun Sep 06, 2009 7:31 am
by jackpf
How about
Code: Select all
if(document.getElementById('image').tagName == 'img')// it's an image
Re: Identify Image
Posted: Mon Sep 07, 2009 1:56 am
by pcoder
Thanks jackpf, worked!!
Re: Identify Image
Posted: Mon Sep 07, 2009 10:11 am
by jackpf
Cool
