Reputation: 953
i want to add additional space characters in my code in Jquery appendto. How can i add it programmatically? I have searched a number of discussions, but none are quite similar to my problem. My code shown below:
$("<div>", {
'class': "main_container",
'id':'bot1',
text: 'item_taken | item_sold', //i want to add spaces between
css: {
"background-color": "#6699cc"
}
}).appendTo('#somediv');
Thank you
Upvotes: 1
Views: 1811
Reputation: 1059
Use HTML instead of text and you can use [ ] or [&emsp] (Equal to tab)
$("<div>", {
'class': "main_container",
'id':'bot1',
html: 'item_taken   |   item_sold',
css: {
"background-color": "#6699cc"
}
}).appendTo('#somediv');
Working demo : https://jsbin.com/saxogo/edit?html,js,output
Upvotes: 2
Reputation: 5246
Use
to give space. And use html instead of text as below.
$("<div>", {
'class': "main_container",
'id':'bot1',
html: 'item_taken | item_sold', //i want to add spaces between
css: {
"background-color": "#6699cc"
}
}).appendTo('#somediv');
$("<div>", {
'class': "main_container",
'id':'bot1',
html: 'item_taken | item_sold', //i want to add spaces between
css: {
"background-color": "#6699cc"
}
}).appendTo('#somediv');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="somediv"></div>
Upvotes: 1