Reputation: 691
I want to add divs after every input in my form:
$("#step1 .left input").after("<div class='form_valid' id='form_valid_" + $(this).attr('id') + "'></div>")
but all generated divs have id = "form_valid_undefined". I dont know why becouse every input have an id.
Upvotes: 2
Views: 226
Reputation: 1774
$("#step1 .left input").each(function(){
$(this).after("<div class='form_valid' id='form_valid_" + this.id + "'></div>");
});
Upvotes: 0
Reputation: 382122
after accepts a function as parameter, so that you can refer to your input element :
$("#step1 .left input").after(function(){
return "<div class='form_valid' id='form_valid_" + this.id + "'></div>"
});
Upvotes: 3