javascript - How would I use a data-attribute in HTML to fill a link and image source with a link from a database? -
i have database has table column called "link" holds link such "http://www.google.com", , column called "image" holds "http://www.placehold.it/500x500".
i have following html:
<a href="" data-field="link"> <img src="" data-field="image"> </a>
i have php backend uses json , jquery plugin retrieve , populate information don't know how fill href"" , src"" attributes specifically.
how can jquery/javascript?
is the thing want?
$("a[data-field='link']").attr("href",yourvalue); $("img[data-field='image']").attr("src",youranothervalue);
Comments
Post a Comment