javascript - How to wrap two elements into one div? -
i have problem wrapping 2 elements: label , input 1 div. can me how right ? thank much.
example:
<label><label> <input> <label></label> <input>
should be:
<div data-role="fieldcontain"> <label><label> <input> </div> <div data-role="fieldcontain"> <label><label> <input> </div>
jquery:
$('input[type="text"]').prev().andself().wrap('<div data-role="fieldcontain">');
html:
<label>name: </label> <input type="text" name="name" id="name" value="" /> <label>surname: </label> <input type="text" name="surname" id="surname" value="" />
you need loop through each input
club input , label , use .wrapall() like
$('input[type="text"]').each(function () { $(this).prev().addback().wrapall('<div data-role="fieldcontain">'); })
demo: fiddle
Comments
Post a Comment