Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Hash Navigation

Tags:

jquery

hash

I have a simple javascript function to get hash variables:

$(document).ready(function(){
    $("a").click(function(){
        nav_anchor()
    });
    function nav_anchor() {
        var aurl = location.hash;
        aurl = aurl.split('#');
        if (aurl[1]) { alert(aurl[1]); }
        else { alert("Empty");  }
    }
}); 
<a href="#a=1&aa=10">11111111111</a>
<a href="#b=1&bb=10">22222222222222</a>
<a href="#c=1&cc=10">333333333</a>

But if I click in the link I receive the previous var.

Example:

If my first Click is 11111 I receive message Empty and if my second click is 222222 I receive a=1&aa=10

like image 894
user835059 Avatar asked Mar 28 '26 10:03

user835059


1 Answers

http://jsbin.com/uxitoy/2/edit

$(document).ready(function(){
    $("a").click(function(){
        nav_anchor(this);
    });
    function nav_anchor(o) {
        var aurl = o.hash;
        aurl = aurl.split('#');
        if (aurl[1].length>0) { alert(aurl[1]); }
        else { alert("Empty");  }
    }
}); 
like image 135
Royi Namir Avatar answered Mar 30 '26 00:03

Royi Namir