:text JQ Home  <<  Selectors  <<  :text

Form text selector.

Shorthand version $(':text')

Description

The :text selector, selects all elements of type text.

Being a jQuery extension the :text pseudo selector is not part of any current CSS specification. Therefore :text cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method.

The same results can be achieved with valid CSS using $('[type=text]'), 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(':text')Form text pseudo-class match

Parameters

None.

Return

N/A.

:text Example Selectors  <<  Top

Selects all elements of type text.

In the example below we apply an orange background to 'text' elements within the form when the button is clicked.


$(function(){
  $('.ourform').submit(function () { return false; }); // disable submit 
  $('#btn10').on('click', function() {
    $('form input:text').css('backgroundColor', 'orange');
  });
});

Pie Survey     

Userame:      

Password:               

     

Which pie do you prefer?:

Select a pie shape: 

            

Press the button below to action the above code:

Related Tutorials

jQuery Basic Tutorials - Lesson 4 - jQuery Selectors