What is the difference between jQuery text and html

0 votes

What the difference between text() and html() functions in jQuery ?

$("#div").html('<a href="example.html">Link</a><b>hello</b>');

vs

$("#div").text('<a href="example.html">Link</a><b>hello</b>');
Nov 25, 2020 in JQuery by kartik
• 37,510 points
264 views

1 answer to this question.

0 votes

Hello @kartik,

The text() method entity-escapes any HTML that is passed into it. Use text() when you want to insert HTML code that will be visible to people who view the page.

Technically, your second example produces:

&lt;a href="example.html"&gt;Link&lt;/a&gt;&lt;b&gt;hello&lt;/b&gt;

which would be rendered in the browser as:

<a href="example.html">Link</a><b>hello</b>

Your first example will be rendered as an actual link and some bold text.

answered Nov 25, 2020 by Niroj
• 82,800 points

Related Questions In JQuery

0 votes
1 answer

What is the difference between AJAX with JavaScript and jQuery?

JavaScript is a programming language. JQuery is ...READ MORE

answered May 30 in JQuery by gaurav
• 22,040 points
146 views
0 votes
1 answer

JQuery Difference between hide() and fadeOut() , show() and fadeIn()

Main difference between FadeIn, FadeOut vs hide, ...READ MORE

answered Jun 1 in JQuery by Edureka
• 13,640 points
43 views
0 votes
1 answer

What is the official correct way to declare jQuery variables?

Declare a variable using the var keyword. Initialize ...READ MORE

answered Jun 2 in JQuery by Edureka
• 13,640 points
1,452 views
0 votes
1 answer

difference between $ and $() in jQuery

JavaScript: It is a major scripting programming language ...READ MORE

answered Jun 10 in JQuery by rajatha
• 7,480 points
58 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,800 points
16,321 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,800 points
1,873 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,800 points
1,563 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,800 points
22,903 views
0 votes
1 answer

What is the equivalent of jQuery .hide() to set visibility: hidden

Hello Kartik, There isn't one built in but ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,800 points
7,753 views
0 votes
1 answer

jQuery Event : Detect changes to the html/text of a div

Hello, If you don't want use timer and ...READ MORE

answered Nov 25, 2020 in JQuery by Niroj
• 82,800 points
11,766 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP