Would like to use jQuery to:
- select any punctuation marks (meaning
.,;:'"“”‘’etc.) that occur directly before and after any links and then - wrap the punctuation marks in
spans.
Hence this:
<div id="mydiv">
Lorem ipsum
<a href="#">dolor sit amet</a>,
consectetur
“<a href="#">adipisicing elit</a>”.
</div>
to become this:
<div id="mydiv">
Lorem ipsum
<a href="#">dolor sit amet</a><span>,</span>
consectetur
<span>“</span><a href="#">adipisicing elit</a><span>”.</span>
</div>
(BTW, &ldquo and ” are quotation marks.)
The content in the div is not fixed. There may also be instances where there’s more than one punctuation mark adjacent to a link (as in the above, ”. to become <span>”.</span>)
Would really appreciate any help!!
Sorta similar (but not quite) to this question with regards to selecting text nodes? Using jQuery, how to modify text outside of tags?
This seems to work:
Try it out: http://jsfiddle.net/GutKg/1/
EDIT: Updated to exclude alphanumeric characters adjacent to the tags.