Balvinder Rayat Balvinder Rayat - 1 year ago 83
jQuery Question

each loop for insertafter failing

I am trying to add

<span class='validation'></span>
after each
<label class="control-label">
. I have tried following but it's adding span class multiple times after each label.

I have also tried using
after control label class but didn't worked.

I want to add same class for each select as well. will adding select inside
$('#myform :input')

what is wrong in this code.

$('#myform :input').each(function(){
$( "<span class='validation'></span>").insertAfter(".control-label");


<div class="col-sm-12">
<label for="Rec_Name" class="control-label">Your Name :</label>
<input class="form-control" type="text" id="Rec_Name" name="Rec_Name" placeholder="Enter Your Name">

Answer Source

Because you add span to after each control-label class.

Try like this:


Maybe a little crazy but should work. Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download