Let's say I have the sentence:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
inside a <p>
tag. I would like to somehow use javascript to create an element around the word amet
, e.g.:
Lorem ipsum dolor sit <span>amet</span>, consectetur adipiscing elit.
Is there some sort of way to do this? In the real-world application for this, I won't know what text I want to have an element around, so I can't just modify the HTML.
One option is using
replace
method.http://jsfiddle.net/YxMvq/