Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2005, 06:46 AM
Registered User
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding multiple spaces

Hello again,
Does anyone know how to add multiple whitespace characters to a text element in JAvscript?
E.g.,
// get a <p> tag
var p = document.getElemenById("para1");

//this only adds 1 space.
p.appendChild(document.createTextNode(" "));

// this adds literal "&nbsp;&nbsp;"
p.appendChild(document.createTextNode("&nbsp;&nbsp ;"));

as does #160;

I'm sure this has an easy solution but it doesn't appear to be in my "Beginning Javsscript" book.

Thanks in advance for any suggestions,

Richard

 
Old March 3rd, 2005, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Unless you're using a <pre> tag, multiple spaces get collapsed into one space by all browsers in line with the HTML specification.
 
Old March 3rd, 2005, 11:00 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Try adjusting the innerHTML instead of creating a text node:
Code:
p.innerHTML = "&nbsp;&nbsp;";

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
adding multiple records Vince_421 VB Databases Basics 4 February 28th, 2007 07:22 AM
adding multiple records at the same time Vince_421 Access VBA 14 February 1st, 2007 10:28 AM
Compensate for a space or multiple spaces crmpicco Excel VBA 5 May 3rd, 2005 01:49 PM
Ouch: 80004005 (adding multiple records) PeterVR Classic ASP Databases 7 September 14th, 2004 06:36 AM
Adding multiple form field values to database cdenequolo Classic ASP Basics 1 August 17th, 2004 05:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.