v3ntus
v3ntus

Reputation: 239

jQuery Load not parsing HTML Variable

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.

Upvotes: 0

Views: 35

Answers (1)

user6748331
user6748331

Reputation:

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>

Upvotes: 1

Related Questions