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

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

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

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


        
16条回答
  •  终归单人心
    2020-11-22 04:17

    $('.div').html(val) will set the HTML values of all selected elements, $('.div').text(val) will set the text values of all selected elements.

    API docs for jQuery.text()

    API docs for jQuery.html()

    I would guess that they correspond to Node#textContent and Element#innerHTML, respectively. (Gecko DOM references).

提交回复
热议问题