Convert HTML string into Jquery Object

前端 未结 2 1241
不知归路
不知归路 2021-02-12 12:25

I have a HTML string which is a mix of text plus HTML tags, which i\'m trying to convert into an object. So for e.g. my HTML string would look like:

Pay using yo         


        
2条回答
  •  死守一世寂寞
    2021-02-12 12:59

    Use

    $.parseHTML()
    

    instead of

    $(HTMLSTRING)
    

    See below JS Code..

    var HTMLSTRING = 'Pay using your  or your ';
    
    var HTMLSTRING1 = ' or your ';
    
    console.log($.parseHTML(HTMLSTRING));
    console.log($.parseHTML(HTMLSTRING1));
    

    Demo Fiddle

提交回复
热议问题