The right way parse html to jQuery object

后端 未结 2 1162
梦毁少年i
梦毁少年i 2021-02-14 07:38

I want to parse a html string to jQuery object then find an element by ID.

I tried 3 ways bellow, but only the last works. I don\'t know why the others not works?

<
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 08:26

    An alternate way to do this -

    var myTestDiv = document.createElement('div');
    var mystr = '
    '; myTestDiv.innerHTML = mystr; console.log(myTestDiv.querySelector('div#main'));

提交回复
热议问题