html - Use jQuery to wrap text after element -
what have:
a checkbox inside label.
<label for="foo"> <input type="checkbox" id="foo" />bar </label> what need:
using jquery, need to wrap text following checkbox (i.e. "bar"), in span element.
<label for="foo"> <input type="checkbox" id="foo" /><span>bar</span> </label> what i've tried:
$('label').wrapinner('<span></span>'); this not exclude checkbox required.
if want wrap text node, filter contents of element based on whether nodetype property 3 (which value of text node), , wrap returned text node.
$('label').contents().filter(function () { return this.nodetype === 3; }).wrap('<span></span>'); alternatively, if know text node next sibling of input element, select next sibling node using nextsibling property:
$('label input').each(function () { $(this.nextsibling).wrap('<span></span>'); });
Comments
Post a Comment