Thursday, 29 August 2013

jQuery / javascript: find character and wrap the word(s) containing it

jQuery / javascript: find character and wrap the word(s) containing it

I'm trying to wrap all words in my texts that contain one or more hyphens
"-" into a span so I can add a no-linebreak css rule. Unfortunately I have
no idea how to achieve this. Any ideas/hints would be greatly appreciated.
Thanks!
Example:
Before: <p>This product is ready-to-use.</p>
After: <p>This product is <span class="nbr">ready-to-use</span>.</p>

No comments:

Post a Comment