What is the difference between jQuery: text() and html() ?

后端 未结 16 1468
傲寒
傲寒 2020-11-22 03:45

What the difference between text() and html() functions in jQuery ?

$(\"#div\").html(\'Linkhello\         


        
16条回答
  •  心在旅途
    2020-11-22 04:38

    The different is .html() evaluate as a html, .text() avaluate as a text.
    Consider a block of html
    HTML

    This is a div container a text after ul

    JS

    var out1 = $('#mydiv').html();
    var out2 = $('#mydiv').text();
    console.log(out1) // This output all the html tag
    console.log(out2) // This is output just the text 'This is a div container Link 1 Link 2 a text after ul'
    

    The illustration is from this link http://api.jquery.com/text/

提交回复
热议问题