I have tested the following code on w3schools.com; however, when I tried it on my local machine it does not work. I have a feeling that the cause is that I do not have the file jquery.js. I was thinking that it was only part of the jquery script declaration and no more. What is written in jquery.js? Is there an alternative file I can include?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<button>Click me</button>
</body>
</html>
You can either change this line
to
Which will load the jQuery library from google CDN(Content Delivery Network). There are several other CDN, check the list here http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery
Or
Load https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js in browser and save the file as
jquery.jsin the directory where your above file is and your code will work fine.Check this tutorial for more details http://docs.jquery.com/How_jQuery_Works