Jquery set content methods set the content of the HTML elements. These methods when calls for setter method of jquery, contain argument to pass inside the function. This argument change the content of the element.

Below are the different types of jQuery set content methods with simple and useful examples.

jQuery Set Content Using text()

The text() set the inner text content of the HTML element and change inner conten by passing an argument with the function. See the below example to check how you can pass the argument and change the content.

Output


This is a paragraph to Show jQuery text method.

The example contains the paragraph with a strong tag inside it to make text bold. When you click on the button, an alert message appears, which contains only the text and not the strong tag.

jQuery Get Content Using html()

jQuery html() set the inner HTML content of the HTML element with tag names you can as an argument. The function change the content and add the HTML content and replace the old content.

Output


This is a paragraph to Show jQuery HTML method.

How to Set Value Using val()

jQuery val() sets the inner value of the content of the HTML element by passing the value as an argument of the function. You can get the value of the HTML element using the val() without any argument and if you want to change the value you can pass some argument with the function.

Output




Set Attribute Using jQuery attr() Method

If you want to set and change the attribute content of the HTML element, you have to use jQuery attr() with come argument to pass with the function. Suppose you have an anchor tag and you want to change the href attribute of it. You have to pass the two argument in which the first argument is the attribute and the second argument is the value of the atribute you want to change or set. See the below example to find out how you can set attribute.

Output



jQuery Animation Effect

Leave a Reply

Your email address will not be published. Required fields are marked *