91-9990449935 0120-4256464 |
jQuery html()jQuery html() method is used to change the entire content of the selected elements. It replaces the selected element content with new contents. Note: It is a very useful function but works in a limited area because of its API documentation. The API documentation of the jQuery html function consists of three method signatures. The first method signature has no argument, so it just returns the HTML within that element. The remaining two signatures take a single argument: i.e. a string or a function that returns a string. Syntax: It is used to return content. It is used to set content. It is used to set content by calling function. The jQuery html() method is used either for set the content or return the content of the selected elements.
The text() method is used to set or return only the text content of the selected elements. Parameters of jQuery html() method
Example of jQuery html() methodLet's take an example to demonstrate jQuery html() method. It is changing the content of all p elements. Test it NowOutput: This is a paragraph. This is another paragraph. jQuery html() example 2Let's see another example of jQuery html() method that returns HTML content. It returns the content of first paragraph only. Test it NowOutput: This is first paragraph. This is another paragraph. jQuery html() example 3Let's see another example of jQuery html() method that converts HTML to text. Test it NowOutput: Click here to change the html to text
Next TopicjQuery text()
|