Pretty green on this. Any ideas why this works:
$('.myclass div').append(' <a ">HELLO WORLD</a>').click(this.function);
and this doesn’t:
$('.myclass div').after(' <a ">HELLO WORLD</a>').click(this.function);
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In both cases, you’re adding the handler to the
divthat was originally selected. Because events bubble, the first one will still work even tough the handler is on the parent of the<a>.If you want the
aelement after thediv, you need to bind directly to thea.You can use
.insertAfter()instead to accomplish this…