Reputation: 19
I have a span with id SOMEID.When I am accessing its text value using folloing code it is breaking in IE8 and IE7 only.How to fix it.
$("#DocumentPath").text()
. If DocumentPath contain name like My doc.txt
it is not working. Note here there is 3 white space between My and doc.
Upvotes: 0
Views: 477
Reputation: 150
Maybe you should try another approach, on jQuery's docs they recommend call .eval()
function to retrieve a value instead of .text()
check their doc:http://api.jquery.com/text/
So the code snippet could be:
$("#DocumentPath").eval()
Regards
:)
Upvotes: 0
Reputation: 51201
You very vague problem description "code it is breaking" can make us only guess, but note the following: IE treats whitespaces in the markup differently than other browsers.
From the docs:
(Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.)
The result of the .text() method is a string containing the combined text of all matched elements.
As of jQuery 1.4, the .text() method returns the value of text and CDATA nodes as well as element nodes.
Thus said, it may be more appropriate for you, to use the html()
method.
Upvotes: 2
Reputation: 29714
Should be
$("#DocumentPath").html()
That said you say your span has an id SOMEID?! If it's id is SOMEID it should be:
$("#SOMEID").html()
Upvotes: 0