image selector

The selector :image selects elements of type image, which are images for form submission. The equivalent of $(':image') is $('[type=image]'). Since :image is not part of the CSS specification, for better performance in modern browsers it is better to use [type='image'] instead.

Syntax

This is how we select elements with type image:

javascript$(':image');

Example

Let's select all inputs with type image and give them a green background and a red border using the css method:

html<form>
  <input type="button" value="button">
  <input type="file">
  <input type="password">
  <button>button</button>
  <input type="reset">
  <input type="radio" name="test">
  <input type="radio" name="test">
  <input type="checkbox">
  <input type="image">
  <input type="text">
</form>
javascript$('input:image').css({background: 'green', border: '2px red solid'});

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

See also

  • 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
  • selector submit,
    which selects elements with type submit that are form submit buttons