Thursday, September 27, 2012

jQuery attribute exists selector


The jQuery attribute exists selector is used to filter out all elements in a page which have the specified attribute, the syntax for this selector is.

$([attribute name])

In this post we shall see on how to use the jQuery attribute exists selector to select all elements in a page which have a specific attribute.

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

    $("[border]").each(function() {
        alert('Attribute Exists Selector:' + $(this).attr('id'));
    });

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

$('#btnAttributeSelector).click(function(event) {
    event.preventDefault();               
    //
    // Attribute - Attribute Exists Selector
    $("[border]").each(function() {
        alert('Attribute Exists Selector:' + $(this).attr('id'));
    });
});

Search Flipkart Products:
Flipkart.com

No comments: