MozillaZine

How to get the selected tag name ?

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

Post Posted March 17th, 2015, 9:48 pm

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.

DanRaisch
Moderator

User avatar
 
Posts: 119904
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted March 18th, 2015, 4:15 am

Moving to Web Development.

Frenzie

User avatar
 
Posts: 2134
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted March 18th, 2015, 4:29 am

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

Post Posted March 18th, 2015, 8:06 am

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

User avatar
 
Posts: 39896
Joined: August 22nd, 2005, 7:25 am

Post Posted March 18th, 2015, 8:32 am

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.

Frenzie

User avatar
 
Posts: 2134
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted March 18th, 2015, 10:11 am

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

User avatar
 
Posts: 10142
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted March 19th, 2015, 10:27 pm

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

Post Posted March 23rd, 2015, 8:02 pm

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 !

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 2 guests