I'm trying to get the hash of a url and compare it to a list of href's in a list. Below is the relevant portion of my code
//ON PAGE LOAD
var hash = document.URL.substr(document.URL.indexOf('#')+1);
hash = '#' + hash;
if(hash)
{
$( "#tab ul li a" ).each(function( index ) {
if(hash==$(this).attr('href'))
{
alert(index);
return index;
}
});
}
alert(index);
//DO STUFF WITH INDEX
The problem is that the nested function isn't returning the index value (its definitely being set). The first alert is returning a number - the second however is returning undefined.
How do I go about returning the index of the matched value?