jquery - dynamically adding image src using javascript -


i trying add image src image in div on click of thumbnail. problem image src not change when thumnail clicked.

html code is:

  <a class="thumbnail" href="#" >      <img  src="img1">      <img  src="img2">      <img  src="img3">   </a>     <div  class="imageforthumb">     <img class="imageforthumbs">  </div> 

javascript im using is:

$('.thumbnail').click(function () { var images = $('.thumbnail img').attr('src'); $(".imageforthumbs").attr('src', images) }); 

once click first image img1, set img1 , not change img2 when click thumbnail. please advice wrong here ?

your js code incorrect. try

$('.thumbnail').click(function (eve) {     $(".imageforthumbs").attr('src', $(eve.target).attr('src')); }); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -