javascript - jQuery wrap label around plain text -
javascript - jQuery wrap label around plain text -
i want wrap label around plain text doesn't have target it.
for example, this:
<div class="checbox"> <input type="checkbox"> text </div>
should become:
<div class="checbox"> <input type="checkbox"> <label>some text</label> </div>
if modify html trivial, cannot.
with jquery how wrap "some text" label?
if html construction constant then, want wrap lastly kid of div class checkbox
class="snippet-code-js lang-js prettyprint-override">$($('.checbox')[0].lastchild).wrap('<label />')
class="snippet-code-css lang-css prettyprint-override">label { color: reddish }
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="checbox"> <input type="checkbox" /> text </div>
if have multiple elements then
class="snippet-code-js lang-js prettyprint-override">$('.checbox').each(function(){ $(this.lastchild).wrap('<label />') })
class="snippet-code-css lang-css prettyprint-override">label { color: reddish }
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="checbox"> <input type="checkbox" /> text </div> <div class="checbox"> <input type="checkbox" /> text 2 </div>
javascript jquery
Comments
Post a Comment