-3

$("#foo").on("click", function (event) {
  alert($(this).text());
});

$("#foo").trigger("click");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<a id="foo" class="fancybox.iframe btn btn-primary" href="addDepartment.jsp" >Next Page</a>

when the page is loaded alert box shows the "Next Page" , but fancybox doesn't open up .
If I physically click on that button(link) then it is working fine.

Deepak Pandey
  • 1,322
  • 12
  • 21

1 Answers1

0
<script>
    $("#foo").on("click", function (event) {
        alert($(this).text());
    });
    $("#foo").trigger("click");
   $( "#foo").unbind( "click" );

</script>

Working Fiddle

Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73