adspace


What is the difference between text() and html() in jquery?

Answer Posted / Shyam Babu

Both `text()` and `html()` are used to get or set content within an element, but they differ in how they handle HTML tags. When you use `text()`, it removes any HTML tags within the selected elements and only returns the text content. If you want to set text content while preserving HTML tags, use `html()`. Conversely, when you use `html()` to get content, it returns the complete HTML markup of the matched elements, including their children and any HTML tags.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to validate email using jquery?

975


How can jquery library be added to pages?

952


How to always reference latest version of jquery?

875


How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.

999


Do you have plans for a new jquery plug-in or something else we should look out for? Where to from here for the imgpreview plugin?

864


What is the minimum setup needed to start using jquery.

939