0

I have a Menu and i am clciking on it using the line

  $("#swipecontainer .swiper-slide").eq(centervalue).trigger("click");

But i see that never the event listener is getting fired .

This is my code

 $(document).on("click", ".swiper-slide", function() {
        alert('i am called');
    });

http://jsfiddle.net/cod7ceho/61/

Could you please let me know how to resolve this .

Pawan
  • 31,545
  • 102
  • 256
  • 434

1 Answers1

1

You need to define the event before making the call to it.

 $(document).on("click", ".swiper-slide", function() {
      alert('i am called');
 });
 $("#swipecontainer").append(favoriteresultag).trigger("create");
 $("#swipecontainer .swiper-slide").eq(centervalue).trigger("click");

http://jsfiddle.net/nx33jez6/

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • dont know that placing of code is also important , thank yiu that resolved my issue . – Pawan Mar 25 '15 at 07:12
  • @PreethiJain: glad it helps :). you can have a look at this solution to know the event attached to element http://stackoverflow.com/a/2008622/1719752. this way you can verify whether event is attached or not. – Milind Anantwar Mar 25 '15 at 07:15