How to set   using JavaScript

Posted on 2004-10-18
Last Modified: 2009-07-29

          I wants to add space to the element in my site using javascript. How can i add " " (dynamically) using javascript?

Question by:b_rajathilagam
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Accepted Solution

minichicken earned 500 total points
ID: 12345193
Looking for this?

If you want to insert a non-breaking space you can insert it using the
charactor code. Like this:

var nbsp = document.createTextNode( "\u00A0" );            
referenceToWhereYouWantIt.appendChild( nbsp );

LVL 25

Expert Comment

ID: 12345300
where do you want add the space? maybe you need just style margin or padding.

var myElement=getElementById("myDiv");"10px";"10px";"10px";"10px";"10px";"10px";"10px";"10px";

//or short hand"10px 10px 10px 10px";"10px 10px 10px 10px";


Expert Comment

ID: 12345377
Hi rajathilagam,
Check this HTML page .....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE>Add Space</TITLE>
<script language=javascript>
      function fnAddSpace()
            var place=document.getElementById("place");
            place.innerHTML="&nbsp;" + place.innerHTML;
<Div id=place><Font Color=Red><B>Helooooo There!</b></Font></Div>
<input type=button onclick="fnAddSpace();" Value="Add a Space">

Hope it helps you....
LVL 18

Expert Comment

ID: 12347947
What does "add space to the element" mean?

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question