Your problem is not the event firing. Your problem, as stated above is they way you are trying to access the button. You are missing the "#" before the id of "Button1". Also, if your button is an ASP.NET button, you'll need to access it this way:
You are mixing JavaScript syntax with jQuery syntax. It should have #in front of Button1 what others have already told you. You can study the various selectors at
http://api.jquery.com/category/selectors/
richardqiaol...
Member
98 Points
39 Posts
the event of $(document).ready ??
Dec 22, 2010 12:45 AM|LINK
i has the problem about the event of $(document).ready
in my situation, the html page contains a button named "Button1"
and i write the following code in my html page.
it doesnt work.
$(document).ready(function() { // alert("sddsfa"); $("Button1").click(function() { alert("sddsfa"); return false; }) })but it works when add the sentence which is commentedSGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: the event of $(document).ready ??
Dec 22, 2010 01:34 AM|LINK
Your selector is incorrect. You should study them and make yourself a cheat sheet.
#Button1 will match the control with the ID of Button1.
My blog
adrenterpris...
Member
495 Points
90 Posts
Re: the event of $(document).ready ??
Dec 22, 2010 03:18 AM|LINK
Hi Richard,
Your problem is not the event firing. Your problem, as stated above is they way you are trying to access the button. You are missing the "#" before the id of "Button1". Also, if your button is an ASP.NET button, you'll need to access it this way:
$("#<%=Button1.ClientID %>").click(function() {....
Take a look at my article on accessing jQuery controls here: http://webdeveloperpost.com/Articles/Accessing-controls-in-jQuery-and-their-attributes.aspx
Visit my website: Tampa Web Design
asteranup
All-Star
30184 Points
4906 Posts
Re: the event of $(document).ready ??
Dec 22, 2010 03:19 AM|LINK
Hi,
If the id of the button is Button1 then replace-
$("input[name=Button1]")Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
raghav_khung...
All-Star
32835 Points
5563 Posts
MVP
Re: the event of $(document).ready ??
Dec 22, 2010 06:14 AM|LINK
You are mixing JavaScript syntax with jQuery syntax. It should have #in front of Button1 what others have already told you. You can study the various selectors at http://api.jquery.com/category/selectors/
shaimonu
Member
259 Points
83 Posts
Re: the event of $(document).ready ??
Dec 22, 2010 11:46 AM|LINK
Try This !!!
$(function() { $("input#Button1").click(function(e) { alert("Hi there"); e.preventDefault(); }) ; });Shaitender