Uncaught TypeError: Cannot set property 'onchange' of null

后端 未结 3 1090
臣服心动
臣服心动 2021-01-05 15:46

I am using a drop down for dynamically changing content on a page. It works but is throwing a js error in Chrome ONLY. What Chrome recommends I don\'t know how to implement.

3条回答
  •  一生所求
    2021-01-05 15:51

    There's only one possible reason for that error message, document.getElementById("drop") does not return the element, and the only reason for that is that the element doesn't exists, but in the HTML it clearly does, so the script must be running before the elements in the DOM.

    You have to include the javascript after the elements in the DOM, or wrap it in a DOM ready handler, like window.onload etc.

提交回复
热议问题