Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#8815 closed bug (invalid)

jQuery's html() function removes tabs in IE 8 when it shouldn't

Reported by: tim@… Owned by:
Priority: low Milestone: 1.next
Component: manipulation Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:


See jsFiddle here:


Notice that in setting the HTML of somediv using the html() function, there are four tabs. In the latest Chrome, Safari, and Firefox, these tabs remain: i.e, there is a tab character at the beginning of each line. However, in Internet Explorer 8, all tab characters following the first are removed.

Note that I'm setting the HTML from the server that has characters saved in the data. This is for a contenteditable div used for rich text editing within my application.

Change History (4)

comment:1 Changed 9 years ago by anonymous

That last part should say: *tab* characters saved in the data.

comment:2 Changed 9 years ago by timmywil

Component: unfiledmanipulation
Priority: undecidedlow
Status: newopen

comment:3 Changed 9 years ago by john

Resolution: invalid
Status: openclosed

I think the issue is that you're conflating HTML (where whitespace tends to be insignificant) and text/pre - where you should probably be using .text("your text") instead. You should just convert the <br>s to \n and you'll be good to go!

comment:4 Changed 9 years ago by tim@…

Why would this work correctly (correctly being that the tab is preserved) in every other browser but IE?

I can't use text() because I'm pulling HTML across the wire so it can be placed into a contenteditable div (think, text editor). To work around this, I need to add a <tab> html tag before the html() command, then replace all <tab> tags with the actual tab character. In javascript, the data flows like this:

Get data from server, with tab character -> convert to <tab> -> use html() -> convert <tab> back to tab character.

This seems like the perfect place for jQuery.

Note: See TracTickets for help on using tickets.