For example I have code:
HTML:
...<input type="text">...
And I would like get this input (I can have more inputs) and 'insert' in to new created element e.g <div>
in the same place.
Result:
...<div><input type="text"></div>...
This code working half correctly, because it inserts input to new element, but with 'copy' all input from page.
jQuery:
$('input').after('<div class="inp_cont"/>').append("div.inp_cont");
I tried with .detach()
$('input').after('<div class="inp_cont"/>').detach().append("div.inp_cont");
This creates a new element, but don't insert input
inside.
I haven't idea how resolve my problem.
Just use
wrap()
:If you want to wrap all elements, matched by the same selector, with the same element:
References:
wrap()
.wrapAll()
.