So I have been looking for this question around and still didn't find an answer. I know how to add a single space with the append method in jQuery but don't know how to add multiple spaces.
Example:
<div id="#myDiv"> hey? <span class="space"></span> my name<span class="space"></span> is coding enthusiast<span class="space"></span> .....</di>
I want the output to be like this:
Hey my name is coding enthusiast ......
I have tried Jquery append, it gives me nothing like that.
//1st try
$('space').append(" ");
//2nd try
$('space').append("       ");
//2nd try output: hey   my name   is coding enthusiast   ....
I feel like I am missing something small. Any ideas?
Edit: Had a typo in my code's question which misled some people when answering:
//1st try
$('.space').append(" ");
//2nd try
$('.space').append("       ");
//2nd try output: hey   my name   is coding enthusiast   ....
So I have been looking for this question around and still didn't find an answer. I know how to add a single space with the append method in jQuery but don't know how to add multiple spaces.
Example:
<div id="#myDiv"> hey? <span class="space"></span> my name<span class="space"></span> is coding enthusiast<span class="space"></span> .....</di>
I want the output to be like this:
Hey my name is coding enthusiast ......
I have tried Jquery append, it gives me nothing like that.
//1st try
$('space').append(" ");
//2nd try
$('space').append("       ");
//2nd try output: hey   my name   is coding enthusiast   ....
I feel like I am missing something small. Any ideas?
Edit: Had a typo in my code's question which misled some people when answering:
//1st try
$('.space').append(" ");
//2nd try
$('.space').append("       ");
//2nd try output: hey   my name   is coding enthusiast   ....
Share
Improve this question
edited Apr 27, 2019 at 13:56
Shiladitya
12.2k17 gold badges28 silver badges42 bronze badges
asked Jun 7, 2015 at 4:43
Coding EnthusiastCoding Enthusiast
3,9331 gold badge31 silver badges50 bronze badges
0
4 Answers
Reset to default 3fixed, forgot semicolon, Thanks to Jake's ment(which he deleted already), I could fix this issue.
$('.space').append(" ");
You are not selecting your elements correctly and add semicolon. Try this:
$('.space').append(" ");
You need to include the .
to specify you're selecting by a class, and add a semicolon after nbsp
(as Jake Opena pointed out.)
$('.space').append(" ");
A different approach could be something like this: https://jsfiddle/fvLxxwa4/
Use this styling for .space:
.space {
margin-left: 50px;
}