[Solved] Get src of .this image inside {{each}}-iteration with jQuery

Hi, I have created an image-pool where people can upload their images for later use.

I got stuck on that part where people click on a image and it’s src-attribute would be inserted inside an input-tag. The problem is that I can’t figure out how to target them with “this” since the images are iterated in an {{each}}-iteration

<input type="text" id="choosenPic">
 {{#each ImagesPool}}
 <img class="placePic" src="http://localhost:3000{{_downloadRoute}}/{{_collectionName}}/{{_id}}/original/{{_id}}{{extensionWithDot}}" width="100px" max-height= "100px">  

I tried using an event like so:

'click .placePic'(event, template) {
  var pic = template.$('.placePic').attr('src');

But this only inserts the first image-src of the iteration inside the text-input.

I thought I could use it like this but it didn’t seem to work

  var pic = this.$('.placePic').attr('src');

The error in this case is "this is not a function"

Any help would be appreciated!

var pic = event.target.src;

1 Like

Ah, I was so close solving this on my own. I even used event.target.src but in the wrong constellation. I’m sorry.

Thank you though.

1 Like