0

I have an out of the box theme that works fine using jquery events to trigger certain effects in both the header and the sidebar parts of the page.

Since there are many pages, I've tried to take those header, sidebar and footer sections, and move the code into external files, which are included with the following javascript strategy:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function{
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

The problem is that when the header and sidebar codes are included using the javascript the jquery events stop working. Is there either a better way to include an external file so that javascripts called in the parent file will affect all elements in the child files? Or, is the something else that I can do?

1 Answers1

1

You can use .on() or .live() method for bind dynamically added element.

Jquery .on() method for dynamically added element - See http://api.jquery.com/on/#direct-and-delegated-events

Use jQuery's live() method. Description: Attach an event handler for all elements which match the current selector, now and in the future.

Try in Jsfiddle

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75