Friday, September 28, 2012

jQuery attribute with type and value IN selector


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

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

In this post we shall see on how to use the jQuery attribute with type and value IN selector to select all text elements in a page which have the class attribute, and a value of
RedText for the class.

The following script lists out all the text elements in the page which have the attributeclass” with the value “RedText
 
    $("input[type=text][class='RedText']").each(function() {

        alert('Attribute with Type(text) and Value IN Selector:' +            $(this).attr('id'));
    });

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

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

Search Flipkart Products:
Flipkart.com

No comments: