Skip to content Skip to sidebar Skip to footer

How To Call A Script Inside A Script

I am currently working on this responsive gallery content and it is working the way I wanted it to. However, I needed to have one of the contents have a content change upon clickin

Solution 1:

Your script is not working because your <a> is not in page when you are trying to bind events to them.

You need to do delegate which is something like this.

<scripttype="text/javascript">
    $(document).ready(function() {
      $(document).on("click", "a", function() {
        var id = $(this).attr("data-id"); // Using a custom attribute.
        $("#pages div").hide(); // gather all the div tags under the element with the id pages and hide them.
        $(".div" + id).show(); // Show the div with the class of .divX where X is the number stored in the data-id of the object that was clicked.
      });
    });
  </script>

This will bind event to document, which is in page from start.

More on jQuery api here.

Post a Comment for "How To Call A Script Inside A Script"