What are the drawbacks of accessing DOM elements directly by ID?

后端 未结 3 1770
孤街浪徒
孤街浪徒 2020-12-19 19:54

Today I stumbled upon the possibility to access a DOM element in Javascript simply by its id e.g. like this:

elementid.style.backgroundColor = \"blue\"
         


        
3条回答
  •  情歌与酒
    2020-12-19 20:46

    It is propriety Microsoft gubbins. It doesn't work in lots of browsers — especially in standards mode (and you want standards mode to avoid quirks mode inconsistencies such as IE getting width wrong).

提交回复
热议问题