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

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

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

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


        
16条回答
  •  余生分开走
    2020-11-22 04:16

    Basically, $("#div").html uses element.innerHTML to set contents, and $("#div").text (probably) uses element.textContent.

    http://docs.jquery.com/Attributes/html:

    Set the html contents of every matched element
    

    http://docs.jquery.com/Attributes/text:

    Similar to html(), but escapes HTML (replace "<" and ">" with their HTML 
    entities).
    

提交回复
热议问题