Parsing of html string using jquery

前端 未结 7 1674
[愿得一人]
[愿得一人] 2020-12-01 01:41

I am trying to parse this html through jQuery to get data1, data2, data3. While I do get data2 and data3 I am unable to get data3 with my approach. I am fairly new to jQuery

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

    I don't know any other way than placing the HTML in an temporary invisible container.

    $(document).ready(function(){
      var datahtml = $("

    data1

    data2

    data3

    ".replace("\\", "")); var tempContainer = $('
    '+ datahtml +'
    '); $('body').append(tempContainer); alert($(tempContainer).find('.class1').text()); $(tempContainer).remove(); }); ​

    Here is a jsfiddle demo.

提交回复
热议问题