How do I make the Jquery of the second page work?

Answer by A Quora admin:

Approach 1 (Recommendation for Static pages): Write all your scripts that need to be reused in a separate file with the extension .js; Similarly if you want the styles to be used across the pages write it in a separate .css file.
Now all you need to do is add a script tag referencing the location of the script.
e.g if you have your .js file that you have common scripts in the same folder as your other HTML pages add "<script src="filename.js" type="text/javascript"/>" in each page. Similarly for your common styles, usually referred as themes, "<link rel="stylesheet" type="text/css" href="filename.css">"

If you are having your javascript files or the stylesheets in different folders you are expected to give the entire path of the file for the src/href attribute.

Approach 2 (Recommendation for dynamic pages) : you can either use single page application (SPA) in which whenever your menu item is clicked an AJAX call will be made to do data binding in a div/ generating the dynamic HTML,
Sharing with you an example from my jsfiddle: Knockout Tutorial 3 – JSFiddle
There is one more approach, usually while developing web application with the help of server side scripting like ASP.NET etc, In which we use Master pages concept that preserves the templates and the general scripts as they are referred only in the master pages and all the child pages reuses them. In this case also, we need to add the references only in the master page.

Hope it helps, let me know if you need further assistance.

How do I make the Jquery of the second page work?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s