Getting and setting content

tutorial and example
tutorial and example

Retrieving and setting text, values and HTML is the simplest aspect of manipulation of DOM. It seems same but they’re not.

There are text(), html() and val() methods.

jQuery html() method

Using the jQuery HTML method, you can change the entire content of the selected element and replace them with the new content.

Here is the example of get the content:

Try Now

Here is the example of set the content with the jQuery html() methods:

Try Now

jQuery text() method

jQuery text() method is used to set or return the text content of selected elements without HTML markup.

Using the jQuery HTML method, you can change the entire content of the selected element and replace them with the new content.

Here is the example to get the content using the text() method:

Here is the example of set the content using the text() method:

Try Now

jQuery val() method

jQuery val() method is used to set or return the value of form fields.

It is used to get first element’s current value in the set of matched elements and also set every matched element value.

To get the value of an input field using the val() method:

Try Now

Here the example to set the value of an input field using the val() method:

Try Now