Is Element.tagName always uppercase?

前端 未结 5 1947
醉酒成梦
醉酒成梦 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:30

    My tests show that the tagName of SVG elements seems to be lowercase in all browsers I checked in August 2018 (Chrome 68, Firefox 61, Edge 42, IE11)

    Not sure how that relates to the "DOM trees" mentioned in the MDN docs - maybe SVG trees are handled separately/differently despite of them being part of the DOM tree. In the end, developers do typically speak of "SVG elements" and "DOM elements", as in pointing out that they're not the same thing.

    In any case, if your application needs to handle SVG elements as well as regular DOM elements, make sure to use tagName.toUpperCase().

提交回复
热议问题