Frontend Questions

Frontend Questions

  1. Why assigning too many ids to html elements is not a good practice? Ref
  • Elements with id will be global variables and properties on window object.

    • This leads to more bugs, like if there’s a var with the same name of an id of a DOM node.
  • If there’s a built-in global property or property of window with the same name as the id of some DOM node, it will not be overriden by the id attribute.

  • Example:

1
2
3
4
5
<html>
<body>
<p id="p1">Hello</p>
</body>
</html>

Global id

2.

Author

Chendongtian

Posted on

2022-12-09

Updated on

2023-08-04

Licensed under

Comments