Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    Why is this simple click not working

    Hello,

    I have tried click, live, bind. If I just put an alert in the ready function, I get the alert. Nothing seems to work for the click function.

    Code:
    $(document).ready(function(){
    			$("#prevButton").click("click",function(){alert("You clicked the previous button.");});
    			
    			
    	});
    Code:
    <input id="prevButton "type="button">Previous</input>
    	<input id="nextButton "type="button">Next</input>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,395
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Why would you want to specify "click" as the first parameter to the .click() event handler? Just remove it ... you would only need it for .bind(), .live() or .on()

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by devnull69 View Post
    Why would you want to specify "click" as the first parameter to the .click() event handler? Just remove it ... you would only need it for .bind(), .live() or .on()
    Dang it. It was not in there when I tried the click earlier, then I tried live, on ,etc. It still does not work.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    he means do it like this

    Code:
    $(document).ready(function(){
    			$("#prevButton").click(function(){alert("You clicked the previous button.");});
    			
    			
    	});

  • #5
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DanInMa View Post
    he means do it like this

    Code:
    $(document).ready(function(){
    			$("#prevButton").click(function(){alert("You clicked the previous button.");});
    			
    			
    	});
    That's what I had when I started. Not working for me. No errors. No idea.

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by m2244 View Post
    That's what I had when I started. Not working for me. No errors. No idea.
    then something else is wrong. i take it this isnt the only code on the page?

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You need to remove the space(s) in the ids:

    Code:
    <input id="prevButton "type="button">Previous</input>
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •