“getElementById not a function” when trying to parse an AJAX response?

后端 未结 3 651
死守一世寂寞
死守一世寂寞 2020-11-29 10:36

I\'m running GM_xmlhttpRequest (in a Greasemonkey script) and storing the responseText into a newly created HTML element:

var respo         


        
3条回答
  •  悲哀的现实
    2020-11-29 11:31

    getElementById is not a method of HTML elements. It is a method of the document node. As such you can't do:

    div.getElementById('foo'); // invalid code
    

    You can implement your own function to search the DOM by recursively going through children. On newer browsers you can even use the querySelector method. For minimal development you can use libraries like jQuery or sizzle.js (the query engine behind jQuery).

提交回复
热议问题