Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  69] [ 7]  / answers: 1 / hits: 20730  / 13 Years ago, mon, december 19, 2011, 12:00:00

I was wondering how can I append a space after an element in JavaScript? I am creating an image and a span in for loop, and I want to append a space after the image and after the span. Here is how I create the tags:



var image = document.createElement(img);

More From » html

 Answers
32

Since you asked for some visual whitespace - the simplest and most flexible way is applying it through CSS, not using a space character:



img {
margin-right: 5px;
}


If you want to only apply it to the specific element you create, you can use JavaScript to apply the CSS: http://jsfiddle.net/aRcPE/.



image.style.marginRight = 5px; // foo-bar becomes fooBar since
// the hyphen is not allowed in this notation

[#88485] Saturday, December 17, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristopher

Total Points: 58
Total Questions: 103
Total Answers: 102

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;