Is Element.tagName always uppercase?

前端 未结 5 1950
醉酒成梦
醉酒成梦 2020-12-29 19:13

Reading at MDN about Element.tagName it states:

On HTML elements in DOM trees flagged as HTML documents, tagName returns the element name in the upper

5条回答
  •  一生所求
    2020-12-29 19:34

    Work with element.tagName.toLowerCase() if your code requires the output in lower case. If the standards change in the future to lowercase then you would not get a different value in your output since it's formatted to lowercase anyway.

    On the contrary, if you left it without toLowerCase() then your code output can change if the standards are changed to output as lowercase.

    I doubt the standard will change for this though. This is entirely up to your needs.

提交回复
热议问题