Jquery click event not firing in firefox

This function attaches the fancybox plugin to some images. When an image is clicked on the image slider, it opens the corresponding larger image inside the div #hidden images. It works in Internet Explorer, but does not work in Firefox (3.6.9). How to make it work in Firefox?

<script type="text/javascript">
   $(document).ready(function() {
       $("#hidden_images a").fancybox(); 
       $("#image_slider img").click(function(event) {
           var $tgt = $(event.target);
           var $desc = $tgt.attr("longdesc");
           $("#" + $desc).click();   
       });
   });
</script>

Here is my HTML:

<div id="image_slider" class="imageflow">
    <img src="images/press/charity1.jpg" longdesc="charity1"  width="250" height="250" alt="Charity 1" />
    <img src="images/press/charity2.jpg" longdesc="charity2"  width="250" height="250" alt="Charity 2" />
</div>
<div id="hidden_images">
    <a id="charity1" href="images/press/charity1_lg.jpg" style="display:none;"><img src="images/press/charity1_lg.jpg" alt="charity one caption"/></a>
    <a id="charity2" href="images/press/charity2_lg.jpg" style="display:none;"><img src="images/press/charity2_lg.jpg" alt="charity two caption"/></a>
</div>
+3
source share
4 answers

For all purposes and goals, you can have the attribute foo = "bar", and this will work anyway. This is how I would encode the inside of your jquery

<script type="text/javascript">
   $(document).ready(function() {
       $("#hidden_images a").fancybox(); 
       $("#image_slider img").click(function(event) {
           window.location = $("#" + $(event.target).attr("longdesc")).attr("href");
       });
   });
</script>

Works for me on safari, ff and chrome.

Derr, , , , ...

2 AHA Moment, .

$("#" + $(event.target).attr("longdesc")).fancybox().trigger("click");
+2

longdesc, . Internet Explorer DOM, , FireFox . alt , , jquery data.

+3

, firefox onclick.

: , fancybox, .

googling, URL, . 3-4 . , HTML- onclick anchors, Mozilla, IE-7, IE-8, Safari .

onclick="$('a.pop{$key}').fancybox().trigger('click');" 

//  { @$key = Use your dynamic id  }

, , .

+1

, click firefox, , "span". "button" .

html : <span class="some-class"> : <button class="some-class">

Javascript:

$(document).on('click','.some-class',function(){alert( "Test click event.");});

, .

0
source

Source: https://habr.com/ru/post/1764056/


All Articles