Reputation: 2215
I am getting text from rich text box
For exmaple : "abc def" .
I am supposed to show a drop down box at those white spaces but browsers are eleminating tose white spaces automatically.
I have tried this code :
var text = div.innerHTML;
var regex = new RegExp(" ", "g");
text = text.replace(regex, " ");
div.innerHTML = text; '
this keeps the proper alignment with 2 extra spaces
Is there any way so that I can replace blank space by
in text but if text comes betwwen the tags ex. <font size="10"
then space between font and size will not be replaced
Thanks
Upvotes: 0
Views: 1234
Reputation: 1230
you could use a pre tag in html "<pre>string</pre>"
or make a css class like the pre :
.wspaces{
white-space: pre;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
Upvotes: 0
Reputation: 168249
Set the style of the div to
white-space: pre;
and you don't have to do all the mess with javascript.
Upvotes: 3
Reputation: 54258
use
for double space. Browsers will eliminate extra space by default.
Upvotes: 0