Thursday, September 27, 2012

jQuery attribute value selector


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

$([attribute name = attribute value])

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

The following script lists out all the elements in the page which have the attributeborder”, and a value of 0 for the border attribute

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

The following script lists out all the elements in the page which have the attributeborder”, and a value of 0 for the border attribute, on click of the btnAttributeSelector button.

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

Search Flipkart Products:
Flipkart.com

No comments: