jQuery website jQuery documentation

Events / Form

submit(Function fn) : jQuery

fnFunctionA function to bind to the submit event on each of the matched elements.

Bind a function to the submit event of each matched element.

Example

Prevents the form submission when the input has no value entered.

Before
<form id="myform"><input /></form>
Code
$("#myform").submit( function() {
  return $("input", this).val().length > 0;
} );

submit() : jQuery

Trigger the submit event of each matched element. This causes all of the functions that have been bound to thet submit event to be executed.

Note: This does not execute the submit method of the form element! If you need to submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();

Example

Triggers all submit events registered for forms, but does not submit the form

Code
$("form").submit();

onesubmit(Function fn) : jQuery

fnFunctionA function to bind to the submit event on each of the matched elements.

Bind a function to the submit event of each matched element, which will only be executed once. Unlike a call to the normal .submit() method, calling .onesubmit() causes the bound function to be only executed the first time it is triggered, and never again (unless it is re-bound).

Example

Before
<p onsubmit="alert('Hello');">Hello</p>
Code
$("p").onesubmit( function() { alert("Hello"); } );
Result
alert('Hello'); // Only executed for the first submit

unsubmit(Function fn) : jQuery

fnFunctionA function to unbind from the submit event on each of the matched elements.

Removes a bound submit event from each of the matched elements. You must pass the identical function that was used in the original bind method.

Example

Before
<p onsubmit="myFunction">Hello</p>
Code
$("p").unsubmit( myFunction );
Result
<p>Hello</p>

unsubmit() : jQuery

Removes all bound submit events from each of the matched elements.

Example

Before
<p onsubmit="alert('Hello');">Hello</p>
Code
$("p").unsubmit();
Result
<p>Hello</p>

select(Function fn) : jQuery

fnFunctionA function to bind to the select event on each of the matched elements.

Bind a function to the select event of each matched element.

Example

Before
<p>Hello</p>
Code
$("p").select( function() { alert("Hello"); } );
Result
<p onselect="alert('Hello');">Hello</p>

select() : jQuery

Trigger the select event of each matched element. This causes all of the functions that have been bound to thet select event to be executed.

Example

Before
<p onselect="alert('Hello');">Hello</p>
Code
$("p").select();
Result
alert('Hello');

oneselect(Function fn) : jQuery

fnFunctionA function to bind to the select event on each of the matched elements.

Bind a function to the select event of each matched element, which will only be executed once. Unlike a call to the normal .select() method, calling .oneselect() causes the bound function to be only executed the first time it is triggered, and never again (unless it is re-bound).

Example

Before
<p onselect="alert('Hello');">Hello</p>
Code
$("p").oneselect( function() { alert("Hello"); } );
Result
alert('Hello'); // Only executed for the first select

unselect(Function fn) : jQuery

fnFunctionA function to unbind from the select event on each of the matched elements.

Removes a bound select event from each of the matched elements. You must pass the identical function that was used in the original bind method.

Example

Before
<p onselect="myFunction">Hello</p>
Code
$("p").unselect( myFunction );
Result
<p>Hello</p>

unselect() : jQuery

Removes all bound select events from each of the matched elements.

Example

Before
<p onselect="alert('Hello');">Hello</p>
Code
$("p").unselect();
Result
<p>Hello</p>

change(Function fn) : jQuery

fnFunctionA function to bind to the change event on each of the matched elements.

Bind a function to the change event of each matched element.

Example

Before
<p>Hello</p>
Code
$("p").change( function() { alert("Hello"); } );
Result
<p onchange="alert('Hello');">Hello</p>

change() : jQuery

Trigger the change event of each matched element. This causes all of the functions that have been bound to thet change event to be executed.

Example

Before
<p onchange="alert('Hello');">Hello</p>
Code
$("p").change();
Result
alert('Hello');

onechange(Function fn) : jQuery

fnFunctionA function to bind to the change event on each of the matched elements.

Bind a function to the change event of each matched element, which will only be executed once. Unlike a call to the normal .change() method, calling .onechange() causes the bound function to be only executed the first time it is triggered, and never again (unless it is re-bound).

Example

Before
<p onchange="alert('Hello');">Hello</p>
Code
$("p").onechange( function() { alert("Hello"); } );
Result
alert('Hello'); // Only executed for the first change

unchange(Function fn) : jQuery

fnFunctionA function to unbind from the change event on each of the matched elements.

Removes a bound change event from each of the matched elements. You must pass the identical function that was used in the original bind method.

Example

Before
<p onchange="myFunction">Hello</p>
Code
$("p").unchange( myFunction );
Result
<p>Hello</p>

unchange() : jQuery

Removes all bound change events from each of the matched elements.

Example

Before
<p onchange="alert('Hello');">Hello</p>
Code
$("p").unchange();
Result
<p>Hello</p>