Tuesday, October 16, 2012

Triggering an Event in Jquery with hyperlink href is firing only first time.


Before some days back i have an issue with my Jquerry.I have an hover Event and in that i am Triggering an Click Event.but the Problem is that it execute only first it will not triggering second time.The code is like this

  $(document).ready(function () {
        $(".various1").fancybox().hover(function () {
                    this.click();
            });
        });

so this code is execute for first time when i hover the image.so Replace above code with this it will worked.


  $(document).ready(function () {

            $(".various1").fancybox().hover(function () {
               if (this.click) {
                    this.click();
                 
                } else if (document.createEvent) {
                    if (event.target !== this) {
                        var evt = document.createEvent("MouseEvents");
                        evt.initMouseEvent("click", true, true, window,
          0, 0, 0, 0, 0, false, false, false, false, 0, null);
                        var allowDefault = this.dispatchEvent(evt);
               
                    }
                }

            });
        });

0 comments:

Post a Comment