jquery - Calling a function from one JavaScript file in html -
i wrote javascript in separate file want use function written in .js file
html
<html lang="en"> <head> <title>try</title> </head> <body onload="hide()" > <div id="final"> <p> hello world</p> </div> <script src="js/userfunction.js"></script> </body> </html>
js file
function hide(){ $("#final").hide(); }
its not working, please suggest
you have not included jquery file
<html lang="en"> <head> <title>try</title> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> function hide(){ $("#final").hide(); } </script> </head> <body onload="hide()" > <div id="final"> <p> hello world</p> </div> <script src="js/userfunction.js"></script> </body> </html>
jquery online reference jquery file. may download js file, keep locally in project folder , refer there.
or
if function in "js/userfunction.js", make sure path correct, , if path correct , still not working try loading script file in head tag. script file needs loaded first before functions in called.
Comments
Post a Comment