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



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

Answer / 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

More jQuery Interview Questions

Mention the advantages of cdn? : jQuery Mobile

1 Answers  


Can we include multiple version of jquery? : jquery mobile

1 Answers  


Explain some benefits of jquery knockout?

1 Answers  


Why jQuery is better than JavaScript?

1 Answers  


Explain jquery connect?

1 Answers  


How to search for descendant elements that match the specified selectors using ?

1 Answers  


What is called chaining?

1 Answers  


Define the use jquery.data method?

1 Answers  


Whether our own specific characters are used in place of $ in jQuery?

1 Answers  


How can related code be encapsulated? Give example.

1 Answers  


What is the difference between prop and attr?

1 Answers  


How to disable/enable an element in jquery?

1 Answers  


Categories