473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Outputting white space using innerHTML

I generate several string in a js. I output the strings to an invisible
container using inner.HTML. Then, the container is made visible.

For layout purposes, I want to precede some of the strings with
significant white space. I find that using either multiple spaces within
quotes or a string of   doesn't work. I get one space and the
remainder are ignored. I've even tried a gif spacer with no success. (I
expected as much, but I'm desperate.)

Thoughts or solution I'm overlooking? TIA.
--
Ed Jay (remove 'M' to respond by email)
Apr 19 '06 #1
2 8148
VK
Ed Jay wrote:
For layout purposes, I want to precede some of the strings with
significant white space. I find that using either multiple spaces within
quotes or a string of   doesn't work.


Unless you're using <pre> and other (obsolete) "fixed-layout" tags,
spaces are being collapsed - this is how the HTML works.

Within HTML layout one usually use NON-BREAK SPACE named entity: &nbsp;

JavaScript deals with Unicode-16 characters so it has no idea about
HTML named entities. You have to use Unicode escape sequences instead.
Say Unicode code of NON-BREAK SPACE is 00A0, thus in JavaScript you use
it as "\u00A0":

var str = "\u00A0 \u00A0 String with leading spaces";

P.S. Are you sure that CSS rules are out of help to you? Like say
text-indent: 1em;

Apr 19 '06 #2
VK scribed:
Ed Jay wrote:
For layout purposes, I want to precede some of the strings with
significant white space. I find that using either multiple spaces within
quotes or a string of &nbsp; doesn't work.
Unless you're using <pre> and other (obsolete) "fixed-layout" tags,
spaces are being collapsed - this is how the HTML works.

Within HTML layout one usually use NON-BREAK SPACE named entity: &nbsp;

JavaScript deals with Unicode-16 characters so it has no idea about
HTML named entities. You have to use Unicode escape sequences instead.
Say Unicode code of NON-BREAK SPACE is 00A0, thus in JavaScript you use
it as "\u00A0":

var str = "\u00A0 \u00A0 String with leading spaces";


Ah so! Thanks.
P.S. Are you sure that CSS rules are out of help to you? Like say
text-indent: 1em;


Apparently, unless the string is present when the page is first rendered,
any CSS embedded in the string goes uninterpreted.
--
Ed Jay (remove 'M' to respond by email)
Apr 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lawrence | last post by:
I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space? ..{60} Also, does this match a block of PHP in an...
6
by: Grumble | last post by:
Hello all, I want to read lines from a text file, where each line has the following syntax: token1:token2:token3 There could be white space between tokens and ':'
2
by: Malcolm Dew-Jones | last post by:
I am looking at xslt 1.0 and trying to understand if empty text nodes are supposed to be stripped or not as the default behaviour. 3.4 starts by listing rules for when white space is not stripped...
17
by: Stanimir Stamenkov | last post by:
Is it possible to make two inline elements to appear adjacent stripping any white space appearing in between in the source? Example: <span class="adj">1</span> <span class="adj">2</span>...
2
by: Jerry Sievers | last post by:
tried to avoid using PRE in the page markup and instead used DIV CLASS=foo and assigned the white-space pre property to it. have some reports already that text is not showing as preformatted. ...
0
by: Mark Moore | last post by:
I'm trying to layout a couple text input fields and their corresponding labels without using a table. When I was trying to debug my understanding of CSS, I was *very* surprised to see that span's...
38
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with...
0
by: TR | last post by:
I am adding a Panel to my page at runtime so: '//note that P is another container Panel Dim MyPanel As New System.Web.UI.WebControls.Panel MyPanel.CssClass = "MYPANEL" MyPanel.ID = "p100"...
2
by: shagy | last post by:
Hi, I'm having a problem with a <select><option> which has white space in values... When I post the data I only get the first word (up to the white space). "Testing white space" becomes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.