construct a DOM tree from a string without loading resources (specifically images)

前端 未结 3 521
梦如初夏
梦如初夏 2020-12-20 17:51

So I am grabbing RSS feeds via AJAX. After processing them, I have a html string that I want to manipulate using various jQuery functionality. In order to do this, I need a

3条回答
  •  孤城傲影
    2020-12-20 18:47

    The answer is this:

    var parser = new DOMParser();
    var htmlDoc = parser.parseFromString(htmlString, "text/html");
    var jdoc = $(htmlDoc);
    console.log(jdoc.find('img'));
    

    If you pay attention to your web requests you'll notice that none are made even though the html string is parsed and wrapped by jquery.

提交回复
热议问题