I am trying to wrap elements <label>, <input type="text"/>and an <select>element, <div class="formItem"></div>to fix some provisions in the form that I cannot directly edit. For some reason, when I try to use the following code:
$("label").before("<div class=\"formItem\">");
$("input[type=text]").after("</div>");
$("select").after("</div>");
It doesn’t work. He simply adds <div class="formItem"></div>in front of everyone <label>that does not help me.
I looked at .wrap();but it’s not clear how I can use this to wrap a few elements, as I try to do. Here is an example of HTML markup:
<label>Text Box</label>
<input type="text" name="Text Box" />
<label>Select Menu</label>
<select name="Select Menu">
<option>Example</option>
</select>
There are about 10 sets, 9 text fields and 1 selection box, if that matters.
source
share