Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does tagName method in JavaScript return HTML tags in capital letters?

Why does tagName method in JavaScript return HTML tags in capital letters? HTML tags should be written in small letters.

like image 978
PawelChyla Avatar asked Oct 16 '18 17:10

PawelChyla


People also ask

Should HTML tags be capitalized?

Tag names for HTML elements may be written with any mix of lowercase and uppercase letters that are a case-insensitive match for the names of the elements given in the HTML elements section of this document; that is, tag names are case-insensitive.

What is tagname in JavaScript?

Introduction to JavaScript getElementsByTagName() method The getElementsByTagName() is a method of the document object or a specific DOM element. The getElementsByTagName() method accepts a tag name and returns a live HTMLCollection of elements with the matching tag name in the order which they appear in the document.

Do capital letters matter in JavaScript?

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

Is HTML code case sensitive?

All the HTML elements/tags are case-insensitive. Case-insensitive means the tags/elements which are used in the code are understandable by the browser irrespective of the letters being the upper case or lower case classes.


1 Answers

The older versions of HTML back when JavaScript was first created used all caps for tag names by convention instead of today's lowercase. To stay backward-compatible with older code tagName() still returns all uppercase and has been stuck that way.

like image 191
Rarblack Avatar answered Oct 07 '22 11:10

Rarblack