javascript - How to indentify which image is clicked using ajax in ruby on rails -


i know best way identify image have clicked on webpage can replace div image.

my html page looks -

<div id="image" >     <%= link_to image_tag(@product.image1_url,:width=>180, :height=>180), selection_path, remote: true %> </div> <div id="image2" >     <%= link_to image_tag(@product.image2_url,:width=>80, :height=>80), selection_path, remote: true %> </div> <div id="image3" >     <%= link_to image_tag(@product.image3_url,:width=>80, :height=>80), selection_path, remote: true %> </div> 

now if click on image2 image shown in div id="image" should replaced @product.image2_url. i've created product.js.erb file looks following -

$('#image').html("<%= escape_javascript image_tag(@product.image1_url,width: '250', height: '250') %>"); 

the above js works 1 image., i'm unable write correct jquery code identify image clicked. how identify element clicked. think it's quite i'm new jquery/javascript. let me know useful resources can me learn code in js.erb files.

any pointers appreciated.

thanks in advance!!

you can find closest div of this (current js object):

$('img').click(function() {   clickeddiv = $(this).closest('div');   clickeddiv.html( ... ); // whatsoever want }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -