2

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.

1
  • That's because this doesn't refer to the input elements. Commented Sep 8, 2013 at 7:19

2 Answers 2

3

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>"
});
Sign up to request clarification or add additional context in comments.

Comments

0
$("#step1 .left input").each(function(){
     $(this).after("<div class='form_valid' id='form_valid_" + this.id + "'></div>");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.