Monday, October 1, 2012

jQuery attribute with dropdown type selector


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

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

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

The following script lists out all the dropdown elements in the page which have the attributeclass” which have the value “RedText 

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

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

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

Related Post
jQuery attribute Selectors
jQuery id selector
jQuery class selector
jQuery attribute exists selector
jQuery attribute value selector
jQuery attribute with type selector
jQuery attribute with type and value IN selector
jQuery attribute with type and value NOT IN selector
jQuery attribute with dropdown type selector
jQuery attribute with checkbox type selector
jQuery attribute selector Example

Search Flipkart Products:
Flipkart.com

No comments: