In the following example, we use two jQuery methods: one to add content to the existing HTML tags and another to add new HTML tags in the body.
1. text( ) : The method selects the tag and the argument to the text function appends text to the pre-existing tags. The argument is HTML safe meaning the content will be exactly copied to the tag irrespective of HTML code passed as an argument.
2. html( ) : The method selects the tag and the argument to the html function adds the content to the selected tag. It is HTML specific meaning that it will check if the argument is an HTML content and add it accordingly.
Output: Page after running the above HTML file
After Clicking the “Correct Me!” button
After clicking the “Add Me!” Button
Other Important jQuery functions :
3. css( ) : The method is used to select and manipulate the CSS properties of the element.
4. attr( ) : The method returns and changes the attribute of an HTML tag.
5. val( ) : The method returns value of all the tag which have the value attribute. It can also set the value by passing argument to it.
If one wants to add multiple CSS properties to a tag then the more appropriate method is to give properties to a class and then remove, add or toggle class into a tag. This property makes jQuery very easy to use and handle.
jQuery provides addClass( ), removeClass( ), and toggleClass( ) to add, remove and toggle a class to a tag in HTML.
- How to use .join() with push and replace together?
- How to use complex HTML with twitter Bootstrap tooltip using jQuery ?
- How to use .on and .hover in jQuery ?
- How to replace innerHTML of a div using jQuery?
- Replace live() with on() in jQuery
- How to use input readonly attribute in jQuery ?
- How to use jQuery in Angular ?
- How to use Explode effect in jQuery ?
- How to use the Magnific Popup jQuery plugin?
- How to use jQuery touch events plugin for mobiles ?
- Autocomplete Search using jQuery and Wikipedia OpenSearch API
- How to search JSON tree with the help of jQuery ?
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- Use of blockquote, q and cite tags in HTML
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.