471,896 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

Get Tag Name

Ciary
247 Expert 100+
hi all,

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

Expand|Select|Wrap|Line Numbers
  1. <div id="foo"><p id="bar">test</p><img id="hi" src="hi.jpg"/></div>
  2.  
  3. alert(getTag("foo"));  //would return 'div'
  4. alert(getTag("bar"));  //would return 'p'
  5. alert(getTag("hi"));  //would return 'img'
  6.  
does anyone know how this can be done?
Apr 10 '09 #1
4 13472
acoder
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
Ciary
247 Expert 100+
i didn't know that property existed.
sorry for the basic question and thanks acoder :)
Apr 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
a quick overview what properties are on element nodes.
Apr 10 '09 #4
Ciary
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
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.