views:

12

answers:

2

Hi I have this line in my script to reference any button click on my page

        $("input").click(function() {
      alert ("clicked") ; 
        but_id = (this.id);
        });

It will then work on any input element but I cant seem to reference just a button . I thought this would work but is does not

        $("input :button").click(function() {

can anyone offer any advice please ?

A: 

If it's a submit button, you can do something like this:

$('input[type=submit]').click( function(e){

} );

JQuery is awesome because it has full CSS3 selector support, regardless of whether or not the browser does.

This means you're allowed to use things like first-child and nth-child and your javascript will work, even in older browsers.

For more detail, take a look at attribute selectors or the JQuery selector API.

Mark Biek
+1  A: 

Jquery supports a wide range of selectors. You can select all input buttons and submits by its type by doing:

$('input[type=button], input[type=submit]')
Shawn Mclean