admin管理员组文章数量:1334859
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;
}
本文标签: javascriptAdding multiple(extra) white spaces to span using jQueryStack Overflow
版权声明:本文标题:javascript - Adding multiple(extra) white spaces to span using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742372298a2462465.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论