Wednesday, October 3, 2012

jQuery visible selector for dropdowns


The jQuery visible selector for dropdowns is used to filter out all the dropdown elements in a page.

$("select:visible")

In this post we shall see on how to use the jQuery visible selector for dropdowns selector to select all the dropdown elements in a page.

The following script lists out all the dropdown elements in a page

    $("select:visible").each(function() {
        alert('State - Visible, type = dropdown:' + $(this).attr('id'));
    });

The following script lists out all the dropdown elements in a page on click of the btnStateSelector button.

$('#btnStateSelector).click(function(event) {
    event.preventDefault();               
    //
    // State - Visible, type = dropdown
    $("select:visible").each(function() {
        alert('State - Visible, type = dropdown:' + $(this).attr('id'));
    });
});

Search Flipkart Products:
Flipkart.com

No comments: