html - Jquery code that copies one pictures source to another -


i plan on making lightbox want learn way around javascript. goal when click 1 of images, copies images source , div id of "copiedto"

i cant figure out how code wrong. here html:

<body>     <div id="gallery">         <ul>             <li>                 <img src="1.jpg"/>             </li>             <li>                 <img src="2.jpg"/>             </li>             <li>                 <img src="1.jpg"/>             </li>             <li>                 <img src="2.jpg"/>             </li>             <li>                 <img src="1.jpg"/>             </li>             <li>                 <img src="2.jpg"/>             </li>         </ul>     </div>      <div id="copiedto"><img src="#"/></div> </body> 

and javascript:

$(document).ready(function () {              var image = $(this).attr('src');             $('#gallery ul img').click(function() {             $('#copiedto img').attr('src', image);         });          }); 

thanks.

please update code

$(document).ready(function () {      $('#gallery ul img').click(function() {            var image = $(this).attr('src');            $('#copiedto img').attr('src', image);      }); }); 

also change copiedto copiedto , check working jsfiddle here http://jsfiddle.net/5agmp/


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -