How to get the selected tag name ?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
ar11x
Posts: 90
Joined: January 6th, 2015, 4:45 am

How to get the selected tag name ?

Post by ar11x »

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
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.
User avatar
DanRaisch
Moderator
Posts: 127240
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: How to get the selected tag name ?

Post by DanRaisch »

Moving to Web Development.
User avatar
Frenzie
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium
Contact:

Re: How to get the selected tag name ?

Post by Frenzie »

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.
ar11x
Posts: 90
Joined: January 6th, 2015, 4:45 am

Re: How to get the selected tag name ?

Post by ar11x »

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 !?
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Re: How to get the selected tag name ?

Post by trolly »

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.
User avatar
Frenzie
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium
Contact:

Re: How to get the selected tag name ?

Post by Frenzie »

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.
User avatar
jscher2000
Posts: 11763
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA
Contact:

Re: How to get the selected tag name ?

Post by jscher2000 »

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
ar11x
Posts: 90
Joined: January 6th, 2015, 4:45 am

Re: How to get the selected tag name ?

Post by ar11x »

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 !
Post Reply