I would like to replace the contents of a div with the contents of another div (which is hidden with css) by clicking on the image. However, using several of the methods suggested here, I cannot get it to work.
my code is below:
HTML
<h3>Recent Callaborations</h3> <div id="collaborations"> <img class="rec1" src="http://domain.com/michaelscott/wp-content/uploads/2013/02/url.png"/> <div id="rec1">Some image caption that is hidden now and that will replace what is in the rec div below</div> </div> <div id="rec-box" class="rec"> this is the content that is to be replaced </div>
Js
jQuery(document).ready(function() { jQuery(".rec1").click(function(event) { event.preventDefault() jQuery('#rec-box').html($(this).next('#rec1')[0].outerHTML); }); });
CSS
#collaborations { width: 100%; margin:0 0 10px 0; padding:0; } #collaborations img { display:inline-block; } .rec { background: #EDEDED; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; padding: 10px; } #rec1, #rec2, #rec3, #rec4 { display:none; }
source share