I have a img source I’m trying to prepend but I’m trying to use the variable “id” in the source. I’m having trouble modifying this snippet of code to do that.
$('#photo_850').prepend('<img src= id + ".jpg" />');
thanks for helping me with 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.
Your concatenation was off:
Another, perhaps easier to read, method would be:
This method first creates the element represented by a string in the first parameter. Next, jQuery proceeds to map the members of the object literal to the newly-created HTML element. You can probably guess by now that our newly-created
<img>will have asrcproperty offoo.jpg, assuming the variableidis a string of"foo".