SyntaxStudy
Sign Up
Home jQuery Reference .html() / .text()

.html() / .text()

method

.html() gets/sets the HTML content; .text() gets/sets the text content (HTML-escaped).

Syntax

$(selector).html() $(selector).text()

Example

javascript
// Get content
const html = $('#box').html();
const text = $('#box').text();

// Set content
$('#box').html('<strong>Bold text</strong>');
$('#title').text('New Title');

// Append content
$('#list').append('<li>New item</li>');
$('#list').prepend('<li>First item</li>');