To manipulate the text content of an element with jQuery, you can use the .text()
method or the .html()
method.
Using the .text()
method:
// Get the text content of an element
let textContent = $('#elementId').text();
// Set the text content of an element
$('#elementId').text('New text content');
Using the .html()
method:
// Get the HTML content of an element
let htmlContent = $('#elementId').html();
// Set the HTML content of an element
$('#elementId').html('<span>New HTML content</span>');
Note: The .text()
method treats the content as plain text, while the .html()
method allows you to manipulate the content as HTML.