I would like to build a list of articles with a different thumbnail for each one, and this thumbnail should be loaded using jquery.load, but I have one problem:
The class of each article's thumbnail in html is as follows:
thumb{ARTICLE_ID}
Now, given this basic example:
<i class="thumb{ARTICLE_ID}"></i>
<script>$('thumb{ARTICLE_ID}').load("https://somewebsites.com .itemimg");</script>
How can I Make jQuery parse "{ARTICLE_ID}" variable?
Thank you.
You can achieve it this way, for example:
<i class="thumbnail" data-article-id="{ARTICLE_ID}"></i>
<script>
$('.thumbnail').each(function () {
$(this).load("https://somewebsites.com/" + $(this).data('article-id'))
})
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.