Solved

jQuery question

Posted on 2014-12-26
5
85 Views
Last Modified: 2014-12-26
I don't understand something.

$("#myDiv").text("<b>Boo</b>");

<div id="myDiv"></div>

Open in new window


The browser will actually display '<b>Boo</b>' without boldfacing the word 'Boo'. When I examine the source through the browser's debugger (e.g. webkit), the text doesn't show the output as using HTML entities like &gt; or &lt;, nor are any of the characters escaped in any way.

Can someone please explain to me what's happening here?
0
Comment
Question by:elepil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Assisted Solution

by:Brian Tao
Brian Tao earned 100 total points
ID: 40519289
In jQuery, using .text(str) will display exactly the str you assigned to it.  Please use .html(str).
0
 

Author Comment

by:elepil
ID: 40519291
Taoyipai, thanks for responding. I am aware about html(). My question is how come the text(string) output, despite obviously being escaped, is not showing in View Source or through the browser debugger.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40519293
It won't show in view source because that is the rendered HTML at load, anything you add is in the browsers DOM

Jquery will html encode the < and > etc to their equivalent (&gt; or &lt;) but when you view it the debugger you will see the actual < >
0
 
LVL 58

Accepted Solution

by:
Gary earned 400 total points
ID: 40519294
If you use Firebug and select the element and click edit you will see the encoded characters
Whatever browser you are using for debugging will have similar.
0
 

Author Closing Comment

by:elepil
ID: 40519297
Thanks for all your help!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question