Using jQuery, how can I find the index number of a link clicked on with a matching class name?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="
http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function
() {
$('a.xyz').click(function(
index) {
alert('You clicked on link number ??? with the class name of "xyz".');
return false;
});
});
</script>
</head>
<body>
<h1>Click on a link below.</h1>
<p>
<a href="#" class="xyz">Link</a>
<a href="#" class="xyz">Link</a>
<a href="#" class="xyz">Link</a>
<a href="#" class="xyz">Link</a>
<a href="#" class="xyz">Link</a>
</p>
</body>
</html>