Getting the Content of an HTML Element

var p1Contents = $("#p1").html(); var div1Contents = $("#div1").html();

Containing the content inside an HTML element is easy using the jQuery .html() method. Calling this method with no parameter returns an HTML string version of the content. If the content is just text, the return is a simple string. If the content is HTML elements, the string is included in the HTML tags.

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.