$ (). live is not a function - JavaScript / jQuery

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.

+7
javascript function jquery popup
source share
5 answers

.live() was introduced in jQuery 1.3 , so it will not work with earlier versions.

.live() also deprecated in jQuery 1.7 onwards.

Alternatives: .on() and .delegate()

See the related question jQuery 1.9.live () is not a function on how to migrate existing code.

+9
source share

http://api.jquery.com/live/

Since .live() deprecated from jQuery 1.7+, you should use either .on() or .delegate() .

See the related question jQuery 1.9.live () is not a function on how to migrate existing code.

+27
source share

Tente usar .bind no lugar de .live

Try using .bind instead of .live

+1
source share

For anyone using> = v1.9, see here about wear and tear: jQuery 1.9.live () is not a function

+1
source share

Find this function in wp - includes \ js \ thickbox \ thickbox.js and change the function:

 function tb_init(domChunk){ jQuery(domChunk).live('click', tb_click); } 

Replacing the live method for on, for example:

 function tb_init(domChunk){ jQuery(domChunk).on('click',tb_click); } 

If you use Nivo-Slider, jquery.nivo.slider.js will require similar changes.

0
source share

All Articles