I wanto to insert a space at the start of my string Example:
MySite
MySite (I want this)
I have tried in this mode but nothing
txt=" "+v.text();
Can someone help me? Thanks a lot
I wanto to insert a space at the start of my string Example:
MySite
MySite (I want this)
I have tried in this mode but nothing
txt=" "+v.text();
Can someone help me? Thanks a lot
Share Improve this question edited Jul 3, 2012 at 10:10 Zoltan Toth 47.7k12 gold badges131 silver badges137 bronze badges asked Jul 3, 2012 at 10:09 user1427811user1427811 8- 3 I'm unclear what you want to achieve. Show us the before and after string. If you mean you want to prepend a string with a space, the code you posted is correct (though I don't know why you included five spaces rather than just one). – Mitya Commented Jul 3, 2012 at 10:11
- remember that html browsers fold multiple adjacent whitespaces into one – wroniasty Commented Jul 3, 2012 at 10:11
-
can you do that in
css
instead? – Bob Commented Jul 3, 2012 at 10:12 - Use MySite – coolguy Commented Jul 3, 2012 at 10:12
- and what is the context for this? you only want your txt var to have this spaces or is it inside some kind of html structure? – Th0rndike Commented Jul 3, 2012 at 10:12
4 Answers
Reset to default 7Try :
txt=" "+v.text();
The other good solution would be to use div with some style set on it.
<div style='margin-left:15px' id='main_text'></div>
You could use jQuery to place txt in the div.
txt= v.text();
$('#main_text').html(txt);
A solution is to fill the spaces with
entities, but if you have to achieve this effect just for styling/visualization purpose, then wrap that line in a proper tag and use some CSS instead (e.g. text-indent
property)
if you have to indent text inside a select (as I guess reading your previous answer) you may want to wrap your options inside an optgroup
element (and give it some padding)
var str2 = " Here goes your string with spaces";
There are 2 solutions below :-
1. txt="<pre> </pre>"+v.text();
2. txt="<span style='margin-left:15px'></span>"+v.text();