Replacing Element Text

$("$mySpan").html("content"); . . . $("$mySpan").html("newer content"); . . . $("$mySpan").html("even newer content");

Rather than prepending or appending text (or content, for that matter) to an element, you may want to replace the element content entirely. The simplest way to do this in jQuery is to use .html(), which sets the value of the content to whatever string or object you pass into it, thus replacing the existing content.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.