Wednesday, September 26, 2012

jQuery hyperlink selector


The jQuery hyperlink selector is used to filter out all the hyperlink elements in a page, the syntax for this selector is.

$('a')

In this post we shall see on how to use the jQuery hyperlink selector to select all the hyperlink elements in a page without specifying the id or name of element explicitly.

The following script lists out all the hyperlink elements in the page

    $('a').each(function() {
        alert('HyperLink: ' + $(this).attr('id'));
    }); 

The following script lists out all the hyperlink elements in the page on click of the btnTypeSelector button.

$('#btnTypeSelector').click(function(event) {
    event.preventDefault();               
    //
    // HyperLink - Type Selector
    $('a').each(function() {
        alert('HyperLink: ' + $(this).attr('id'));
    }); 
});

Search Flipkart Products:
Flipkart.com

No comments: