:password
JQ Home <<
Selectors <<
:password
Form password selector.
Shorthand version $(':password')
Description
The :password
selector, selects all elements of type password.
- Being a jQuery extension the
:password
pseudo selector is not part of any current CSS specification. Therefore:password
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. - The same results can be achieved using the Attribute Equals Selector via
$('[type=password]')
, without the hit to performance. - If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.
Syntax
Signature | Description |
---|---|
jQuery(':password') | Form password pseudo-class match |
Parameters
None.
Return
N/A.
:password
Example
Selectors << Top
Selects all elements of type password.
In the example below we apply an orange background to 'password' elements within the form when the button is clicked.
$(function(){
$('.ourform').submit(function () { return false; }); // disable submit
$('#btn1').on('click', function() {
$('form input:password').css('backgroundColor', 'orange');
});
});
Related Tutorials
jQuery Basic Tutorials - Lesson 4 - jQuery Selectors