jquery: fire href but add #hash to it?
/*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-开发者_JS百科wrapper hash at the end?
Right now, when I click a link the link doesn't get fired anymore!
May be this will help.
$('#wpf-wrapper a').live('click',function() {
$(this).attr('href', $(this).attr('href') + "#wpf-wrapper");
});
Hope it helps.
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");
});
});
You could also do a simple redirect
$('#wpf-wrapper a').live('click',function() {
window.location = $(this).attr('href') + "#wpf-wrapper";
});
You don't need to do this onclick
$('#wpf-wrapper a').each(function() {
this.href = this.href + '#wpf-wrapper';
});
精彩评论