Thursday, September 27, 2012

jQuery attribute with type selector


The jQuery attribute with type selector is used to filter out all elements in a page with a specific type, and have the specified attribute, the syntax for this selector is.

$("input[type=<type name>][<attribute name>]")

In this post we shall see on how to use the jQuery attribute with type selector to select all text elements in a page which have the class attribute.

The following script lists out all the text elements in the page which have the attributeclass
 

    $("input[type=text][class]").each(function() {
        alert('Attribute with Type Selector:' + $(this).attr('id'));
    });

The following script lists out all the text elements in a page which have the class attribute, on click of the btnAttributeSelector button.

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

Search Flipkart Products:
Flipkart.com

No comments: