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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -