Reputation: 4500
I want to set "someting "
as the html inside a div, but .html() seem to remove the trailing spaces.
It's inside a contenteditable
div, so when the users starts typing there's a space missing between "something" and what he types.
HTML
<div id="text" contenteditable="true"></div>
JAVASCRIPT
$('div#text').html('something ');
This shows "something_" inside the div, but when you start typing it appears right next to the rest of the text.
Upvotes: 2
Views: 1949
Reputation: 146191
If you like it using css
HTML
<div contenteditable="true" id="test"></div>
CSS
div#test:before{
content: '>\0000a0\0000a0';
/*or content: 'Something\0000a0\0000a0';*/
}
DEMO.
Upvotes: 0
Reputation: 145408
In order to set visible spaces in HTML, they should be in the form of
, e.g.
$("#text").html("something ");
An option is to make basic spaces transformation using your own function:
function spaceToNbsp(str) {
return str.replace(/ /g, " ");
}
$("#text").html(spaceToNbsp("something "));
DEMO: http://jsfiddle.net/NAWY3/
Upvotes: 5
Reputation: 7590
Try using
instead of spaces:
$('#div_id').html("something ");
Upvotes: 1