What does jQuery do differently when you specify the datatype as html as opposed to text. I haven't seen a difference but there must be some subtleties I'm missing. If I wish to return a portion of an html page as a string does it matter which I use?
2 Answers
"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM. "text": A plain text string.
So really the only difference is if you have script tags.
2 Comments
user169867
That's how I would have interpreted it too, but I do have script tags and they run even with "text" as the datatype. At least in IE8 & FF3.6
Samuel
it seems by default jQuery tries to figure out the type for you. i believe text is used to avoid this. so instead of jQuery trying to figure out if it's JSON, xml, script or html it just hands you plain text without worrying about it. (jQuery likes to worry...)
Using this html
<div id="foo">
<span>hello world</span>
</div>
Differences
$("#foo").text(); //=> hello world
$("#foo").html(); //=> <span>hello world</span>
2 Comments
tvanfosson
I think you misunderstood the question.
user169867
Yeah, sorry macek I might not have been clear enough but I was asking about the datatype parameter on the ajax function in jQuery.