Submit selector

The :submit selector selects elements with the type submit, which are form submit buttons. Typically, the :submit selector is applied to buttons or input elements. It is important to remember that some browsers treat the button element as having [type='submit'] implicitly, while others do the opposite. To ensure proper operation, always specify the type property. Since :submit is not part of the CSS specification, it is better to use [type='submit'] instead for better performance in modern browsers.

Syntax

This is how we select elements with type submit:

javascript$(':submit');

Example

Let's, according to the theory above, select all elements with the type submit that are descendants of td elements. Let's give these td a green background and a red border using the css method:

html<form>
  <table border="1" cellpadding="10" align="center">
    <tr><th>Element</th></tr>
    <tr><td><input type="button" value="button"></td></tr>
    <tr><td><input type="file"></td></tr>
    <tr><td><input type="password"></td></tr>
    <tr><td><button>button</button></td></tr>
    <tr><td><input type="reset"></td></tr>
    <tr><td><input type="submit"></td></tr>
    <tr><td><input type="radio" name="test"></td></tr>
    <tr><td><input type="checkbox"></td></tr>
    <tr><td><button type="submit">button</button></td></tr>
    <tr><td><input type="text"></td></tr>
  </table>   
</form>
javascript$('td:submit')
  .parent('td')
  .css({background: 'green', border: '2px red solid'})
  .end();

$('form').submit(function(event) {
  event.preventDefault(); // prevents form submission
});

See also

  • tag button
  • selector button,
    which selects button elements and all elements with type button
  • method filter,
    which filters elements in a set by a given selector
  • method css,
    which allows you to get and change the CSS styles of an element