Tools: Visual Studio 2010
I’m trying to learn jQuery, but I cant make this example work even after trying for 2 hours. I know it’s quite simple but I don’t know what I’m missing.
JQuery is defined here, inside the <head> tag:
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.7.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$("#divTest1").hide();
$("p").hide();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="divTest1">
Itz too much I cant make it work...!
</div>
<h2>
This is a heading</h2>
<p>
This is a paragraph.</p>
<p>
This is another paragraph.</p>
<button>
Click me</button>
</div>
</form>
</body>
Updates:
-
I have tried this
$(document).ready(function () { alert(“Hello”); });
And added breakpoint in firebug/Script,after page load firebug got into the jquery library and the went out of it,but it didn’t showed any popup -
I just changed from “jquery-1.7.1-vsdoc.js” to this “jquery-1.7.1.js” and used simple script to check if itz working
$(document).ready( function(){ alert("Hello"); } );,jquery is working now.
As pointed out by Matt Grande, you’re not actually including the jQuery library in your page. You need to add the following to the
head:The vsdoc version is just to add Intellisense support.
Also, using e.preventDefault() is preferred over returning false;