Thursday, September 27, 2012

jQuery id selector


The jQuery id selector is used to filter out all elements in a page with a specific ID, the syntax for this selector is.

$("#ID")

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

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

    $("#txtName").each(function() {
        alert('ID Selector:' + $(this).attr('id') + ' => ' + $(this).val());
    }); 

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

$('#btnAttributeSelector).click(function(event) {
    event.preventDefault();               
    //
    // Attribute - ID Selector
    $("#txtName").each(function() {
        alert('ID Selector:' + $(this).attr('id') + ' => ' + $(this).val());

Search Flipkart Products:
Flipkart.com

No comments: