jQuery select and wrap textNode

You can use contents, and filter by node type (3 is for text node):

$('div').contents()
        .filter(function(){return this.nodeType === 3})
        .wrap('<b />');

Example: http://jsfiddle.net/nJqKq/8

See also: Node Types, at MDC

Leave a Comment