$() - Iterating Over The Stack Demo

Link Link Link Link Link Link Link

$(
	function(){
	
		// Get a collection of all links.
		var jLinks = $( "a" );
	
		// Get each link and then loop over the stack.
		jLinks.each(
			function( intI, objLink ){
				// Get a jquery verion of the linke.
				var jLink = $( this );
				
				// Set link click handler.
				jLink
					.attr( "href", "javascript:void( 0 )" )
					.click(
						function( objEvent ){
							// Alert index of link.
							alert( "Link Index " + intI + " of " + jLinks.length );
							
							// Prevent default behavior.
							return( false );
						}
						);
				;
			
			}
			);	
			
	}
	);