In Firefox, I unexpectedly received this message from firebug:
$('a.close, #fade').live is not a function
Indeed, when I click on the image gallery and pop-ups. I canβt close it. A click event is never logged due to this error message.
This is the script:
$('a.poplight[href^=#]').click(function() { var popID = $(this).attr('rel'); var popURL = $(this).attr('href'); var query= popURL.split('?'); var dim= query[1].split('&'); var popWidth = dim[0].split('=')[1]; //Fade in the Popup and add close button var div_popup = document.createElement('div'); div_popup.setAttribute('id',popID); div_popup.setAttribute('class','popup_block'); document.body.appendChild(div_popup); $(div_popup).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a> <a href="thumbBg' + $(this).attr('rel').substring($(this).attr('rel').lastIndexOf('p') + 1,$(this).attr('rel').length) + '"></a><p>The Human Diet: By Rene Endara</p>'); var popMargTop = ($('#' + popID).height() + 80) / 2; var popMargLeft = ($('#' + popID).width() + 80) / 2; $('#' + popID).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); $('body').append('<div id="fade"></div>'); $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); return false; }); //Close Popups and Fade Layer $('a.close, #fade').live('click', function() { $('#fade , .popup_block').fadeOut(function() { $('#fade, a.close').remove(); //fade them both out }); return false; });
Markup:
<ul class="thumb"> <li><a href="#?w=500" rel="popup1" class="poplight"><img src="images/thumb1.jpg" alt="" /></a></li> <li><a href="#?w=500" rel="popup2" class="poplight"><img src="images/thumb2.jpg" alt="" /></a></li> <li><a href="#?w=500" rel="popup3" class="poplight"><img src="images/thumb3.jpg" alt="" /></a></li> <li><a href="#?w=500" rel="popup4" class="poplight"><img src="images/thumb4.jpg" alt="" /></a></li> </ul>
Thanks for the answer.
javascript function jquery popup
John merlino
source share