1

This is working in Chrome, but not IE or Firefox. Could someone help please? Thanks

<script type="text/javascript">
if (window.location.hash === "#Location") {

      setTimeout(function() {
        $("#Location").trigger('click');
    },5);         

  } else {

  }
</script>
sierra.charli3
  • 205
  • 2
  • 22

1 Answers1

1

The problem is that your page is not already charged and the click event triggered is lost. On my firefox with jquery loaded this code work properly:

<body>
    <button id="location">toclick</button>
    <script type="text/javascript">

        setTimeout(function() {
            $("#location").trigger('click');
        },100);
        $('#location').click(function(){ console.log('click') });
    </script>
 </body>

Or if you want you can put your script inside the ready() function to wait that the page is loaded completly:

$( document ).ready(function() {
    //code
});
jedi
  • 839
  • 12
  • 33