$(document).ready(function(){ /* the following code is executed once the dom is loaded */ $('.sponsorflip').bind("click",function(){ // $(this) point to the clicked .sponsorflip element (caching it in elem for speed): var elem = $(this); // data('flipped') is a flag we set when we flip the element: if(elem.data('flipped')) { // if the element has already been flipped, use the revertflip method // defined by the plug-in to revert to the default state automatically: elem.revertflip(); // unsetting the flag: elem.data('flipped',false) } else { // using the flip method defined by the plugin: elem.flip({ direction:'lr', speed: 350, onbefore: function(){ // insert the contents of the .sponsordata div (hidden from view with display:none) // into the clicked .sponsorflip div before the flipping animation starts: elem.html(elem.siblings('.sponsordata').html()); } }); // setting the flag: elem.data('flipped',true); } }); });