Search code examples
jquerywebonclickhref

onClick event open page then load function


On #page2, I have an hidden content triggered by the function openContent().

On #page1, I'd like a href tag to load #page2 then load the openContent() function.

I tried to create a onClick event that would do both on #page1 but it doesn't work.

I'm new to jQuery and I must have it all mixed up.

Thanks


Solution

  • Page 1: <a href="page2.html#open">Page 2</a>

    Page 2

    jQuery(document).ready(function($) {
      if(window.location.hash == "open") {
        openContent();
      }
    });