Assign JSON data to the src attribute of an <img> element

Assign JSON data to the src attribute of an <img> element
0

#1

$("#id").html(JSON.obj);

if the above code stores a JSON object into the element with id=“id” as text to the html page.

how do I store the JSON object in this case a URL into an image element’s src attribute ??

$("#id").src(JSON.obj) ?? logic but i know its not right.


#2

Since src is an attribute of $("#id") you can use .attr() to change it.