I'm trying to understand how location.hash works in jQuery, for that, I'm trying to begin from the most basic form, and then once I get that right I'd go deeper, but sadly I'm already stuck at what I think should be a simple thing.
Here's my code I created modifying someone else's code I found in a post here:
$(document).ready(function(){
$("body").css("background-color", "#FF0");
$(window).bind( 'hashchange', function( event ) {
if (window.location.hash == "red"){
$("body").addClass("red");
} else if (window.location.hash == "green") {
$("body").addClass("green");
}
event.preventDefault();
});
$(window).trigger("hashchange");
});
And here's the page http://dlacrem.16mb.com/dlatest/hash.html
Now, as I said, I'm trying to learn so there are probably 80 mistakes in 10 lines :D but, shouldn't it be adding the red class to the body when I go to hash.html#red?
I'm using the BBQ plugin by Ben Alman
Regards, and thanks for any help that comes my way!