-3

Possible Duplicate:
How to replace all periods in a string that aren’t in an html tag?

I have a webpage with a contentEditable div and a submit button. When the user clicks the submit button I want to replace all spaces in the contentEditable div with:

<span class="large"> </span>

The problem I've run into is I don't want any of the spaces within pre-existing HTML tags to get edited, and I also don't want to lose them.

Here's how an example page would be structured:

<div id="content" contenteditable="true">
     <p class="MsoNormal" style="text-indend:.5in">
          Example Text Here
     </p>
</div>

When a use clicks a submit button I want to replace the spaces in "Example Text Here" only. There could be multiple paragraph elements within the content div or there could be none, depending on how the user entered the text into the element.

Community
  • 1
  • 1
Clinton Jooooones
  • 887
  • 3
  • 12
  • 19

1 Answers1

-1

Set an ignore-flag to false.
Walk through the string, one char after another.
...If you encounter a <
......set the ignore-flag to true.
...If you encounter a >
......set the ignore-flag to false.
...If you encounter a space and the ignore-flag is false
......append your substitution.
...Else append the char to your output-string as is.

It's not pretty - Can probably be done with a single regular expression, but I'm a human being : )

T4NK3R
  • 4,245
  • 3
  • 23
  • 25