0

I have the next iteration in a Django template. This shows me a group of images and their title.

    {% for i in blogs %}
        <div class="content__blog">
            <h4 class="content__blog__h4">{{i.title}}</h4>
            <img class="content__blog__img" src="{{i.image.url}}" onclick="clickImage()">
        </div>
    {% endfor %}

What i want to do by adding JavaScript is that when clicking on an Image it'll resize. But only the image clicked. How do i specify in the JS file which image i'm clicking on?

1 Answer 1

1

try something like this

{% for i in blogs %}
    <div class="content__blog">
         <h4 class="content__blog__h4">{{i.title}}</h4>
         <img class="content__blog__img" id="{{i.id}}" src="{{i.image.url}}" onclick="clickImage(this)">
     </div>
{% endfor %}

js

function clickImage(e){
   // e is image element
   alert(e.id)
}
Sign up to request clarification or add additional context in comments.

Comments

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.