Parsing of html string using jquery

前端 未结 7 1670
[愿得一人]
[愿得一人] 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:10

    Try this

    alert($(datahtml).find(".class0 h4").text());
    

    The reason being the text you are referring to is inside h4 element of class0 .. So your selector will not work,, Or access the contents directly..

    alert($(".class0 h4").text()); 
    
    alert($(".class1").text()); 
    
    alert($("#mydivid").text()); 
    

    EDIT

    var datahtml = "

    data1

    data2

    data3

    "; $('body').html(datahtml); alert($(".class0 h4").text()); alert($(".class1").text()); alert($("#mydivid").text());

    CHECK DEMO

提交回复
热议问题