I have two html main.html and a.html
<html> <head> <title> main.html </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function() { $("#y").click(function() { $('#y1').load('a.html'); }); }); </script> </head> <body> <div id="y">link1 </div> <div id="y1">frame </div> </body> </html>
a.html
<html> <head> <title>a.html </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(document).ready(function(){ $("#date").datepicker(); $("#y2").on("click",function(){ alert("clicked data in a.html"); }); }); </script> </head> <body> <div id="y2"> click here to get alert </div> <input id="date" type="text" /> </body> </html>
when I open the a.html file, the datepicker function works well, but open the main.html file by clicking 'link1' to load a.html in main.html datepicker fails and I get an error message in the error firefox console as
>Error: TypeError: $(...).datepicker is not a function >Source File: http://code.jquery.com/jquery-latest.js?_=1362478481277 >Line: 605
[EDITIED to improve my question below]
now my main.html
<html> <head> <title> main.html </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(document).ready(function() { $("#y").click(function() { $('#y1').load('a.html'); }); $("#y4").click(function() { $('#y1').load('b.html'); }); }); </script> </head> <body> <div id="y">link1 </div> <div id="y4">link2 </div> <div id="y1">frame </div> </body> </html>
a.html
<html> <head> <title>a.html </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(document).ready(function(){ $("#date").datepicker(); $("#y2").on("click",function(){ alert("clicked data in a.html"); }); }); </script> </head> <body> <div id="y2"> click here to get alert </div> <input id="date" type="text" /> </body> </html>
b.html
<html> <head> <title>b.html </title> <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(document).ready(function(){ $("#date1").datepicker(); $("#y3").on("click",function(){ alert("clicked data in b.html"); }); }); </script> </head> <body> <div id="y3"> click here to get alert </div> <input id="date1" type="text" /> </body> </html>
source share