Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(this).find('input[type="submit"]:not(.cancel), button').click(function () - what is this?

Can someone help me understand this line of jquery code?:

$(this).find('input[type="submit"]:not(.cancel), button').click(function ()

I'm particularly interested in .cancel, since the whole chunk of jquery code (not included here) is being used to validate a page and I'm trying to prevent the validation if the user clicks on the cancel button. I'm guessing the above line of code is saying it the submit button clicked is NOT the cancel button, then continue.

But I don't know how to designate a button as cancel.

like image 936
merk Avatar asked Oct 12 '11 19:10

merk


People also ask

Why is submit button not working?

Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging. After the Javascript error is fixed, the submit button will automatically be enabled.

How do you know which submit button was clicked in jquery?

activeElement will give you the submit button that was clicked. document. activeElement. getAttribute('value') will give you that button's value.

How do you add a button to a form that does not submit?

The default value for the type attribute of button elements is "submit". Set it to type="button" to produce a button that doesn't submit the form. In the words of the HTML Standard: "Does nothing."


2 Answers

Basically it is looking for elements located within this that has the following requirements

  1. is an input
  2. has type = submit
  3. does not have a class of cancel

OR

  1. is a button
like image 195
John Hartsock Avatar answered Oct 12 '22 08:10

John Hartsock


Good answers here. Perhaps this annotated version adds some value.

$(this)                   // within this jQuery object
  .find('                 // find all elements
    input[type="submit"]  // that are input tags of type "submit"
    :not(.cancel)         // and do not have the class "cancel"
    ,                     // or
    button                // are button elements
  ')
  .click(                 // and for each of these, to their click event
    function (){}         // bind this function
  );
like image 33
Ken Redler Avatar answered Oct 12 '22 10:10

Ken Redler