O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required