469,289 Members | 2,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Get Tag Name

247 Expert 100+
hi all,

does anyone know how i can get the tagtype based on id?

Expand|Select|Wrap|Line Numbers
  1. <div id="foo"><p id="bar">test</p><img id="hi" src="hi.jpg"/></div>
  3. alert(getTag("foo"));  //would return 'div'
  4. alert(getTag("bar"));  //would return 'p'
  5. alert(getTag("hi"));  //would return 'img'
does anyone know how this can be done?
Apr 10 '09 #1
4 13353
16,027 Expert Mod 8TB
Use document.getElementById() to get the element and then use the tagName property to get the tag name/type.
Apr 10 '09 #2
247 Expert 100+
i didn't know that property existed.
sorry for the basic question and thanks acoder :)
Apr 10 '09 #3
8,651 Expert Mod 8TB
a quick overview what properties are on element nodes.
Apr 10 '09 #4
247 Expert 100+
ty Dormilich. that's very usefull :)
Apr 10 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

23 posts views Thread by stewart.midwinter | last post: by
2 posts views Thread by Ravi | last post: by
21 posts views Thread by TheKeith | last post: by
12 posts views Thread by CJ | last post: by
11 posts views Thread by Andrew Thompson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.