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 and Manipulating Element Content

Often, you will not know all the elements that belong on a web page until a user begins using it, or you will receive additional information from a web service or some other interaction. In those cases, you may need to be able to add or replace element content on the fly using jQuery and JavaScript code.

The text of the element content is stored in the innerHTML attribute of the DOM element. You can change the content using JavaScript simply by setting the innerHTML to the new content. For example:

document.getElementById("#p1").innerHTML = "New Text";

In jQuery, you can change the innerHTML content using the .html() method, which gets or sets the innerHTML sting. For ...

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