Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  177] [ 3]  / answers: 1 / hits: 21793  / 10 Years ago, sun, june 1, 2014, 12:00:00

On my express server I'm rendering a page with data as follows:



app.get('/people/:personID', function (req, res) {
res.render(people/profile, {person: req.person });
});


In my profile.ejs file I can access the data in an ejs tag like so: <p><%= person.name %></p>



I can't figure how to change an attribute of an html tag to the value stored in this object though.



This doesn't work: <img id=my_img src=<%= person.picture %> alt=>

or this: $(#my_img).attr(src, <%= person.picture %>);



Also, if there's a better way to pass this document to the html page and access it I'm all ears(or eyes in this case). Thank you


More From » jquery

 Answers
7

You have to include string values within quotes.



In html:



<img id=my_img src=<%= person.picture %> alt=>


In jQuery:



$(#my_img).attr(src, <%= person.picture %>);

[#70773] Thursday, May 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinarnoldp

Total Points: 10
Total Questions: 122
Total Answers: 109

Location: Spain
Member since Thu, Dec 23, 2021
3 Years ago
;