jQuery and general script use help

Far

tsniffer
Staff member
Developer
May 19, 2003
20,179
30
2,783
540
I'm starting to use quite a bit of jquery and java scripts on my page, and the header of each page is starting to become untidy.

Like css, is there any way to hold the script information on another page, so it can be generically used through the site?

for example i have,

Code:
 <link rel="stylesheet" href="../css/style.css">
 <link rel="stylesheet" href="../css/reset.css">

<script type="text/javascript" src="../js/jquery.js"></script>

<script type="text/javascript" >
$(function() 
{
$(".delete").click(function(){
var element = $(this);
var I = element.attr("id");
$('.alert').fadeOut('slow', function() {$(this).remove();});		
return false;
});
});
</script>

is there any way to hold the function in another page, and reference it?
 

GOMEEE

LOMCN Veteran
Veteran
Mar 5, 2009
259
0
42
remove the $(function(){});

put it in a seperate js file and include it like you would a normal js file.

I have been using jQuery for a while and loving it, if i was you i would look into using the live function. saves you having to bind new elements that you introduce to the page via ajax. also i have found (atleast with my scripts) that unless they are placed at the bottom of the page, they dnt always like to work :s. which is another good thing about the live function :D

if ya get any problems, feel free to pm me, i might be able to help ya :p