views:

98

answers:

1

If I have the following line in html:

<span></span> wtf

and then I run the jQuery statement:

$("span").html("test");

It ends up looking like "testwtf" instead of "test wtf". Is there anything I can do about this without changing the html?

+1  A: 

This happens because IE is interpreting the space in <span></span> wtf to be a leading space, and omits it (and interprets the HTML as <span></span>wtf). Because IE is interpreting the HTML differently than other browsers, I don't think there's much you can do without changing the HTML, except doing a workaround like

$CONTAINER.html('<span>test</span> wtf')

or an even more extreme workarounds such as

if (jQuery.browser.msie) $("span").html("test "); else $("span").html("test");

Edit: Preliminary testing shows that $("span").html("test "); by itself is also sufficient.

Zarel