views:

49

answers:

1

Hello, 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 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;
});
A: 
$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");
  }
});
elektronikLexikon
i'm sorry i dont get the idea. can you tell me exact location? cuz i tried your code at everyline it didn't work out
oh, my fault: it should be location.hash, not href. I change that.
elektronikLexikon
yay! it works. thanks a lot :)