Set Content: It is used to set the content using jQuery. The following methods are used to set the content which are listed below:
- text(): It is used to set or return the text content of selected elements.
- html(): It is used to set or return the innerHTML content of the selected element.
- val(): This parameter is used to set or return the value of attribute for the selected elements. This method apply on the HTML form elements.
Example: This example uses set content method (text(), html() and val() method) to set the content.
<!DOCTYPE html> <html> <head> <title>jQuery Set Content</title> <script src= </script> </head> <body style="text-align:center;"> <h1 id="GFG1" style = "color:green;"> GeeksForGeeks </h1> <h2 id="GFG2">jQuery Set Content</h2> <p>Full Form: <input type="text" id="GFG3" value="GFG"></p> <button id="btn1">Set 1 line</button> <button id="btn2">Set 2 line</button> <button id="btn3">Set 3 line</button> <!-- Script to set the content --> <script> $(document).ready(function() { $("#btn1").click(function() { $("#GFG1").text("GEEKSFORGEEKS"); }); $("#btn2").click(function() { $("#GFG2").html("<b>Set Content</b>"); }); $("#btn3").click(function() { $("#GFG3").val("GeeksForGeeks"); }); }); </script> </body> </html> |
Output:
- Before Click on the button:

- After Click on the Set 1 line button:

- After Click on Set 2 line button:

- After Click on Set 3 line button:

Set Attributes: The jQuery attr() method in jQuery is used to set and change attribute values.
Example: This example uses attr() method to set and change attribute values.
<!DOCTYPE html> <html> <head> <title>jQuery Set Attributes</title> <script src= </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>jQuery Set Attributes</h2> <button id="btn1">Click</button> <br><br> <h3> geeksforgeeks.org </a> </h3> <!-- Script to use set attribute method --> <script> $(document).ready(function() { $("button").click(function() { $("#GFG").attr("href", }); }); </script> </body> </html> |
Output:
- Before click on link:

- Click on link before click on button:

- Click on link after click on button:

Recommended Posts:
- jQuery | Get Content and Attributes
- How to copy the content of a div into another div using jQuery ?
- How to insert HTML content into an iFrame using jQuery?
- How to add content in <head> section using jQuery/JavaScript?
- Content editable change event in jQuery
- JQuery | Detect a textbox content is changed or not
- How to detect and change the content/style of a div using jQuery ?
- How to check a selector matches some content using jQuery?
- XML | Attributes
- HTML | Id Attributes
- HTML | Attributes
- HTML | data-* Attributes
- PHP | SimpleXMLElement attributes() Function
- HTML | DOM attributes Property
- HTML | Attributes Complete Reference
- How to get the data attributes of an element using JavaScript ?
- Tags vs Elements vs Attributes in HTML
- Copy all the attributes of one element and apply them to another with JavaScript
- Perl - Attributes in Object Oriented Programming
- Data-toggle attributes in Twitter Bootstrap
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

