0

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your reply. Unfortunately this is not working, no console errors, but nothing is loading. Shouldn't 'article-id' be before the .load?
Provide here your exact code. Problem is unfortunately on your side, this script works.
Thanks for your prompt reply. I started a chat with you, if you have time, thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.