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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -