I wanna get the selected object's tag name and save it as a variable.
But what's the function !?
I knew about Document.getElementById()...but i dont know all about the capturing of 'tag name'
As follow image I wanna the result is 'input'
http://i.imgur.com/HORsGOR.png
How to get the selected tag name ?
-
- Posts: 90
- Joined: January 6th, 2015, 4:45 am
How to get the selected tag name ?
Last edited by Daifne on March 18th, 2015, 8:05 am, edited 1 time in total.
Reason: removed img tags. Size of images breaking forum format.
Reason: removed img tags. Size of images breaking forum format.
- DanRaisch
- Moderator
- Posts: 127243
- Joined: September 23rd, 2004, 8:57 pm
- Location: Somewhere on the right coast
Re: How to get the selected tag name ?
Moving to Web Development.
- Frenzie
- Posts: 2135
- Joined: May 5th, 2004, 10:40 am
- Location: Belgium
- Contact:
Re: How to get the selected tag name ?
You can find a decent practical DOM reference on MDN. The example on the page happens to illustrate the answer your question: https://developer.mozilla.org/en-US/doc ... nt/tagName
Intelligent alien life does exist, otherwise they would have contacted us.
-
- Posts: 90
- Joined: January 6th, 2015, 4:45 am
Re: How to get the selected tag name ?
DanRaisch wrote:Moving to Web Development.
Thanks !
Pardon me.
I am not unfamiliar of this forum.
Frenzie wrote:You can find a decent practical DOM reference on MDN. The example on the page happens to illustrate the answer your question: https://developer.mozilla.org/en-US/doc ... nt/tagName
Hi. Cool method.
But I wanna get the Element what I "selected already".
As above image.I did selected the 'input'(Search bar of Google).
Is any method for this !?
- trolly
- Moderator
- Posts: 39851
- Joined: August 22nd, 2005, 7:25 am
Re: How to get the selected tag name ?
Do you mean in a site script or in Inspector?
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
- Frenzie
- Posts: 2135
- Joined: May 5th, 2004, 10:40 am
- Location: Belgium
- Contact:
Re: How to get the selected tag name ?
I'm a little unclear as to what you mean. To be a little bit more explicit, the tag name of that element would be obtained using:
Code: Select all
document.getElementById('last-ib.whatever').tagName
Intelligent alien life does exist, otherwise they would have contacted us.
- jscher2000
- Posts: 11770
- Joined: December 19th, 2004, 12:26 am
- Location: Silicon Valley, CA USA
- Contact:
Re: How to get the selected tag name ?
If you mean selected as in selected with the mouse, see: https://developer.mozilla.org/docs/Web/API/Selection
If you mean the active/focused form element, see: https://developer.mozilla.org/docs/Web/ ... iveElement
If you mean the active/focused form element, see: https://developer.mozilla.org/docs/Web/ ... iveElement
-
- Posts: 90
- Joined: January 6th, 2015, 4:45 am
Re: How to get the selected tag name ?
jscher2000 wrote:If you mean selected as in selected with the mouse, see: https://developer.mozilla.org/docs/Web/API/Selection
If you mean the active/focused form element, see: https://developer.mozilla.org/docs/Web/ ... iveElement
Sorry about lately response.
Thank you about sharing those docs.
I'll give it a try if it really as I want !