What is the difference between .empty().append() and .html()?

前端 未结 6 1218
心在旅途
心在旅途 2020-12-18 08:27

Using jQuery, what\'s the performance difference between using:

$(\'#somDiv\').empty().append(\'text To Insert\')

and

$(\'         


        
6条回答
  •  旧巷少年郎
    2020-12-18 09:14

    Understand the meaning and functions of the extensions provided in jQuery.

    $('#somDiv').empty().append('text To Insert')
    

    -- Above code will clear the div id tag content first then will append the text to the target div:

    $('#somDiv').html('text To Insert')
    

    -- Above code replace the div tag text with the html text:

提交回复
热议问题