Calling Jquery function in separate file?

Calling Jquery function in separate file?

Hi all

I’m sure this is simple but I can’t work it out.

I have an html file that includes jquery and javascript functions file (functions.js) that contains a simple jquery function.

HTML


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta name="robots" content="noindex, nofollow" />

	<title></title>
	
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
  <script src="js/functions.js" type="text/javascript"></script>

  <script type="text/javascript" charset="utf-8">
    Tester('here');
  </script>

</head>

<body>

</body>
</html>


functions.js


$(document).ready(function(){

	function Tester(name){
    alert(name);
  }
	
	//Tester('here');
	
});


The jquery function works if called from the bottom of the function.js file.

How can I call the function from the html page?

I tried with


<script type="text/javascript" charset="utf-8">
  Tester('here');
</script>

You currently have your Testing function wrapped inside the jQuery DOM ready function which isn’t part of the global scope, simply move it outside the DOM ready function and it will work fine.

Thanks SgtLegend

Do I need the jQuery DOM ready function at all ?

Not at the moment, when you begin writing your jQuery code then you can use the DOM.ready() method.

Sent from my iPhone using Tapatalk