Q:

how to use (location.hash) and (.trigger) to navigate?

i have 5 (div)s all hidden and i use .click function to hide 4 of them and show 1..(1 for each button)
for example :
the html :
<div id="div1">hi<div>
<div id="div2">hello<div>

the jquery:
$("#b1").click(function(){
    $("#div1").hide(500);
    $("#div2").show(500);
});
$("#b2").click(function(){
    $("#div2").hide(500);
    $("#div1").show(500);
});

when i click the b2 the url change to > home#div2
i used location.hash and .trigger
so when the user enter home#div2 in the url the jquery active the b1.click
if(location.hash == "#div2"){
    $("#b1").trigger("click");
}

logicly it should hide div1 and show div2 
but it shows nothing even when i click b1 or b2 manually..
what i am doing wrong ?!

A:

It looks like your problem was caused by your div tags not being terminated correctly. I changed them to: (Notice the forward slash in the tag terminator.)
    <div id="div1">hi</div>
    <div id="div2">hello</div>

This complete example works for me in Chrome:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" language="Javascript" 
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
<script>
$(document).ready(function(){

    $("#b1").click(function(){
        $("#div1").hide(500);
        $("#div2").show(500);
    });

    $("#b2").click(function(){
        $("#div2").hide(500);
        $("#div1").show(500);
    });

    if(window.location.hash == "#div2"){
        $("#b1").trigger("click");
    }
    else if(window.location.hash == "#div1"){
        $("#b2").trigger("click");
    }

    alert(window.location.hash);    
});
</script>
</head>
<body>
    <input type="button" id="b1" value="b1"></input>
    <input type="button" id="b2" value="b2"></input>
    <div id="div1">hi</div>
    <div id="div2">hello</div>
</body>
</html>

