Reading and Writing Content

Reading (getting) & Writing (setting) content

  • Another common pattern with jQuery (and Dom Manipulation in general) is to programmatically read (get / retrieve) and write (set / update) content to and from our pages.

  • The following built-in jQuery methods are frequently used to get and set content:

  • .text()

  • .val()

  • .html()

  // get the text content stored in an element
  $('p.intro').text();

  // set the content to another value
  $('p.intro').text('Updated text that will replace existing content');

JS Bin on jsbin.com

JS Bin on jsbin.com