Friday, April 26, 2019

What is jquery .html() and .append()

$('#').html() will completely replace the content inside the tag that the selector corresponds to. $('#').append() will just append to the end of the content inside the tag.
ex.
$('#foo').html("New content here!");

before: <span id="foo">Old content here!</span>
after: <span id="foo">New content here!</span>
and with append
 $('#foo').append("New content here!");

before: <span id="foo">Old content here!</span>
after: <span id="foo">Old content here!New content here!</span>

No comments:

Post a Comment