I would like to parse the named anchor from the href of a link when it is clicked. How can this be done?
$(document).ready(function(){
$('.my-links').click(function(e){
var href = this.href; // http://example.com#myNamedAnchor
// now parse out just 'myNamedAnchor'
});
});
You can get the anchor with
this.hash. To strip out the#, usethis.hash.substr(1).See the MDN docs.