Wednesday, September 26, 2012

jQuery text selector


The jQuery text selector is used to filter out all the text box elements in a page, the syntax for this selector is.

input[type="text"]


In this post we shall see on how to use the jQuery text selector to select all the textbox elements in a page without specifying the id or name of element explicitly.

The following script lists out all the TextBox elements in the page


$('input[type="text"]').each(function() {
    alert('TextBox: ' + $(this).attr('id'));
});

The following script lists out all the TextBox elements in the page on click of the btnTypeSelector button.

$('#btnTypeSelector').click(function(event) {
    event.preventDefault();               
    //
    // TextBox - Type Selector
    $('input[type="text"]').each(function() {
        alert('TextBox: ' + $(this).attr('id'));
    });
});

Search Flipkart Products:
Flipkart.com

No comments: