I am trying to alert a #
tag on click of an anchor which produces the #
tag.
But I only get an alert after a page refresh:
The anchor:
$folderanchor = "<a class='folderanchor' href='#".$dir.'/'.$file."'>$file</a>";
echo $folderanchor;
Reading the #
:
$( document ).ready(function() {
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
alert (hash);
// hash found
} else {
// No hash found
}
});
The alert should appear immediately after clicking the anchor. What am I doing wrong?