0

I'm trying, using Konvas.js, to click on imgback class and change the background according to the clicked image:

https://jsfiddle.net/hk7xe0we/3/

I do not want to put an id on each image

Following code:

Jquery:

$('.back').click(function(){
    imgback = $('img').attr('src'); 
});

Html

<h2>Background</h2> 
    <span class="back"><img class="img-responsive img-thumbnail" src="http://lorempixel.com/450/400/animals" width="50px"></span>
     <span class="back"><img class="img-responsive img-thumbnail" src="http://lorempixel.com/400/400/city" width="50px" ></span>

Thanks for any help

https://github.com/EditorsJS/editorimagekonvajs

Gislef
  • 1,555
  • 3
  • 14
  • 37
  • whats wrong with the code in your previous question? – Jaromanda X Jan 15 '16 at 05:46
  • The previous question has been settled, I found most organized create a new topic – Gislef Jan 15 '16 at 05:52
  • fair enough - looks like some of the code in that question answers this one though – Jaromanda X Jan 15 '16 at 05:53
  • trying to click on any image background, but always stays the same background https://jsfiddle.net/hk7xe0we/3/. so does the image item https://jsfiddle.net/hk7xe0we/5/ Background and image item together It is confusing https://jsfiddle.net/hk7xe0we/6/ – Gislef Jan 15 '16 at 06:06

1 Answers1

1

When you use this statement

imgback = $('img').attr('src'); 

it gets the first img's src from the html. Instead of doing that, you should get the image from the clicked 'back' element. Which should be:

 imgback = $(this).find('img').attr('src');

I have forked your jsfiddle and updated it. https://jsfiddle.net/1t0qz1rx/2/

Hope that helps!

Jeremy Rajan
  • 662
  • 3
  • 12