html - IE8 doesn't retain my spaces between the string -
i build selectbox through javascript , append div element innerhtml text value options has 2 spaces in between string value. string comparison set selected value fails in ie8 because strips out 1 white space in between. below demo html , script describes issue
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script> function buildselect() { $('#mydiv').html('<select id="listoption1" name="listoption1"><option value="1234">30.0 x 80.0 in</option><option value="12345">32.0 x 80.0 in</option><option value="123">36 x 80 in</option></select>'); } </script> </head> <body onload="buildselect()"> <div id="mydiv"> </div> </body> </html>
in other browsers, 2 spaces (32.0 x 80.0 in) between string retained including ie9.in ie8 doesn't retain those. can suggest solution how have space retained in ie8?
you either use
insert non-breaking spaces or white-space
css property:
white-space: pre;
pre
preserves whitespace without wrapping, pre-wrap
wrap text necessary.
this requires valid doctype in ie8, should present anyway.
Comments
Post a Comment