Cross-browser javascript to get and replace exact HTML from a user's selection?
I'm looking for a way to get, modify, and replace the HTML from a user's selected range using javascript or JQuery. Basically, imagine the user selects a range across some HTML tags (the | delineate the selection):

    <p>This is an <b>example |of</b> some text| to be selected</p>

How would I get:

    of</b> some text

Then further, after running some code to make a modification to that text:

    of some</b> altered text

How would I plug it back in such that the final version reads:

    <p>This is an <b>example of some</b> altered text to be selected</p>

I haven't been able to solve either problem, finding the exact html of a range, or writing specific modified HTML to a range.
Cross-browser javascript to get and replace exact HTML from a user's selection?
===

I'm looking for a way to get, modify, and replace the HTML from a user's selected range using javascript or JQuery. Basically, imagine the user selects a range across some HTML tags (the | delineate the selection):

    <p>This is an <b>example |of</b> some text| to be selected</p>

How would I get:

    of</b> some text

Then further, after running some code to make a modification to that text:

    of some</b> altered text

How would I plug it back in such that the final version reads:

    <p>This is an <b>example of some</b> altered text to be selected</p>

I haven't been able to solve either problem, finding the exact html of a range, or writing specific modified HTML to a range.