Active menu class for current page
i'm making portfolio site template. I have problem about "active link" for my full ajax site.
When i open url (http://bit.ly/d5qNeN) directly, url doesnt come up with addClass
function.
How can i add 'selected' class for directly opened urls?
Here is my开发者_StackOverflow中文版 jquery code, which adds 'selected' class to my navi bar.
$j("a[rel='history']").click(function(){
$j("a[rel='history']").addClass('selected').not(this).removeClass('selected');
// Get the hash from the link that was clicked
// jQuery.history.load("new-hash-value");
var hash = $j(this).attr('href');
hash = hash.replace(/^.*#/, '');
// Load this hash with the history plugin
$j.historyLoad(hash);
$j('#load').fadeIn('normal');
if(!$j('#load').get(0)) {
$j('#content').append('<div id="load"></div>');
}
return false;
});
$j(function() { // on DOM ready
hash = location.hash; // everything after a # in the URL
if(hash) {
// "click" on menu entry that links to expected target
$j("a[rel='history'][href="+hash+"]").trigger("click");
}
});
精彩评论