1

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 ?

2 Answers 2

1

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]')
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.