How can I change image source attribute with var
$(this).attr('src','' +myVar+ '')
var myVar = "img/image.png";
i tried like this.
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.
Is that your actual source code? Because you’re defining the variable after you’re using it. Just switch the lines around. (And no need to do
''+myVar+'', just use the variable directly.)If it still doesn’t work, make sure that
thisrefers to the image element you want to change.