Make IE respect your space with dynamically resized content

If I have the following line in html:

<span></span> wtf

      

and then I ran the jQuery statement:

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

      

It ends up looking like "testwtf" instead of "test wtf". Can I do something about this without changing the html?

+2


source to share


1 answer


This is because IE interprets space in <span></span> wtf

as leading space and omits it (and interprets HTML as <span></span>wtf

). Since IE interprets HTML differently than other browsers, I don't think you can do much without changing the HTML, except that a workaround like

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

      

or even more extreme workarounds like



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

      

Edit: Pretesting shows that $("span").html("test ");

by itself is sufficient as well.

+1


source







All Articles