This answer assumes that you would like to use a client technology (here: jQuery) to modify the DOM.
If you want everything wrapped in one span, then use wrapAll():
$( "div" )
.contents()
.wrapAll( "<span>" );
If you want only text nodes wrapped in the span, then do some filtering:
$( "div" )
.contents()
.filter(function(){return this.nodeType === 3})
.wrapAll( "<span>" );
At last, if you need every node wrapped in its own span, use wrap() instead wrapAll(). You may combine that with filtering as well.
EDIT
If you need to work with marked text, you can combine this with solution to this question: Get the Highlighted/Selected text
I'd say something like this should work:
function getSelectionObj() {
if (window.getSelection) {
return window.getSelection();
} else if (document.selection && document.selection.type != "Control") {
return document.selection.createRange();
}
}
$("button").click(function (){
var o = getSelectionObj();
if(o.anchorNode == null)
return;
var $node1 = $(o.anchorNode);
var $node2 = $(o.focusNode);
var $content = $node1.nextUntil($node2).andSelf();
$content.wrapAll( "<span>" );
});