0
/*Forum maintain scrollposition*/
$('#wpf-wrapper a').each(function() {
    $(this).click(function() {
        $(this).attr('href', $(this).attr('href') + "#wpf-wrapper");
    });
});

I want all my links it his #wpf-wrapper section to be fired normal but get called with a #wpf-wrapper hash at the end?

Right now, when I click a link the link doesn't get fired anymore!

4 Answers 4

2

May be this will help.

$('#wpf-wrapper a').live('click',function() {       
    $(this).attr('href', $(this).attr('href') + "#wpf-wrapper");        
});

Hope it helps.

1
  • thank you, that did the trick! don't know why, but the the live() handler makes it work.
    – matt
    Feb 24, 2011 at 16:10
1

Try this - it rewrites the links as the page loads rather than on click:

$(function() {
    $('#wpf-wrapper a').each(function() {
        $(this).attr('href', $(this).attr('href') + "#wpf-wrapper");
    });
});
1
  • I've already tried that, doesn't make a difference! The link doesn't get fired once I add the hash!
    – matt
    Feb 24, 2011 at 16:09
1

You could also do a simple redirect

$('#wpf-wrapper a').live('click',function() {       
    window.location = $(this).attr('href') + "#wpf-wrapper";        
});
0

You don't need to do this onclick

$('#wpf-wrapper a').each(function() {
    this.href = this.href + '#wpf-wrapper';
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.