JavaScript JavaScript and the DOM Responding to User Interaction The Event Object

Mohammed Munier Hamoud Shikh
Mohammed Munier Hamoud Shikh
1,616 Points

In the Event Object lesson , Why you user event.target.Name=='LI', not 'li'

In the Event Object lesson , Why you user event.target.Name=='LI', not 'li'

Aurelian Spodarec
Aurelian Spodarec
10,787 Points

Hi there!

2months have passed since the question :)

How are you doing with your JavaScript?! ^^

2 Answers

Steven Parker
Steven Parker
179,763 Points

I think you mean "tagName" instead of just "Name", and for HTML documents, "tagName" returns the element name in the uppercase form. So the test compares it with "LI" to check for a match.

See the documentation for Element.tagName for more information.

Kyle Case
Kyle Case
44,857 Points

Any idea why they return the tagName in uppercase? That seems really inconsistent with the rest of the functions in JS.

Steven Parker
Steven Parker
179,763 Points

This is a legacy from the early development of HTML (it was derived from SGML), when tags were conventionally written in upper case.

Stanlon Milow
Stanlon Milow
21,239 Points

Steven Parker You are the man! I was so lost on why tagName returns all capitals but now it makes complete sense. It's legacy that things returned were in capital form so that's why this returns it in "LI". Thank you because I was lost. haha

Steven Parker
Steven Parker
179,763 Points

Thanks for the nice comments, and happy coding!