scrollTo plugin and target focus

scrollTo plugin and target focus

I'm using the following script to successfully scroll links, however, I am having trouble getting the page to focus on the hash target. Instead, the page focus stays with the link that initiates the function rather than the intended target:

  1. $(function(){
        $('a[href*=#]').click(function(){
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
            && location.hostname == this.hostname){  
                var $target = $(this.hash);
                $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
                if ($target.length){
                    var targetOffset = $target.offset().top;
                    $('html,body').animate({scrollTop: targetOffset}, 300);
                    $(this.hash).focus(); // Not working
                    return false;
                }
            }
        });
    });













I've tried using this.hash (as above) and it doesn't work, though I can set the focus to the top of the page like so (not what I want):
  1. $('html,body').focus();
Any ideas where I'm going wrong?

Thanks for your time.

QueryFrog