Using jQuery, what's the performance difference between using:
$('#somDiv').empty().append('text To Insert')
and
$('#somDiv').html('text To Insert')
?
Using jQuery, what's the performance difference between using:
$('#somDiv').empty().append('text To Insert')
and
$('#somDiv').html('text To Insert')
?
.html will overwrite the contents of the DIV.
.append will add to the contents of the DIV.
In simple words:
$('#somDiv').append('blabla')
works like this:
<div id='somDiv'>some text</div>
becomes:
<div id='somDiv'>some textblabla</div>
And innerHTML replaces the contents, so it becomes this:
<div id='somDiv'>blabla</div>
$('#somDiv').html(value)
is equivalent to $('#somDiv').empty().append(value)
.
Source: jQuery source.
The correct syntax is
$("#somDiv").html("<span>Hello world</span>");