function df(){
$(this).text('hello world');
}
bn.attr('onclick','df();');
My problem is $(this) references the jquery window object and not the jquery object bn.
How do I get a dynamic reference to bn in my function df?
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.
Don’t use the
onclickattribute. Use the.click()method:Or the
.on()method (jQuery 1.7+) or.bind()(older versions):Note that there are no invoking parentheses after the function identifier. You need to pass a reference to the function, rather than the return value of the function.