$lightbox.find('.lb-outerContainer').on('click', function(e) { if ($(e.target).attr('id') === 'lightbox') _this.end(); return false; }); 

$lightbox = $('#lightbox'); is the parent of the .lb-outerContainer . If I understand correctly, the “click” should go up the DOM , find the #lightbox element and click on it. ( if ($(e.target).attr('id') === 'lightbox') _this.end(); test will work if ($(e.target).attr('id') === 'lightbox') _this.end(); and the .end() method will be .end() ). But it does not. Can anyone explain why?

Html there such.

alt text .

  • There are no errors in the console? - Smash

2 answers 2

do this

  $lightbox.on('click','.lb-outerContainer', function(e) { if ($(e.target).attr('id') === 'lightbox') _this.end(); return false; }); 

this will hang the event on $ lightbox, it will call your handler.

  • is this code? horror, do not use it to refer to plug-ins on id ... it is necessary to guess - zb '

Why did you decide you should? The click will come to the lightbox, but there is no handler for its click .. the handler will work for the outerContainer, but it will be rejected .. and that's it .. it won't be called a second time.

  • cy6erGn0m, this is not my code. This is a piece of code from the lightbox2 plugin, I'm trying to understand why the author wrote it ... - setback
  • On "#lightbox" there is a handler - $ lightbox.hide (). On ('click', function (e) {if ($ (e.target) .attr ('id') === 'lightbox') _this.end (); return false;}); Most likely it seems to me that the author expected that it would work like this, but why it does not work ... - setback