How to parse HTML from JavaScript in Firefox?

前端 未结 5 1914
无人及你
无人及你 2020-12-01 13:05

What is the best way to parse (get a DOM tree of) a HTML result of XmlHttpRequest in Firefox?

EDIT:

I do not have the DOM tree, I want to acquire i

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 13:43

    innerHTML should work just fine, e.g.

    // This would be after the Ajax request:
    var myHTML = XHR.responseText;
    var tempDiv = document.createElement('div');
    tempDiv.innerHTML = myHTML.replace(//g, '');
    
    // tempDiv now has a DOM structure:
    tempDiv.childNodes;
    tempDiv.getElementsByTagName('a'); // etc. etc.
    

提交回复
热议问题