views:

287

answers:

3

Hi. I have this simple script:

$(document).ready(function(){

var $yoyo = window.location.hash;

alert($yoyo);

});

But I need to get rid of the # symbol as I'll be using the variable to locate div ids. I've tried using .remove('#') but that doesn't seem to be working.

Many thanks in advance!

+5  A: 
var $yoyo = window.location.hash.substring(1);

This simply means we're taking a substring consisting of character 1 (0-indexed, so second) onwards. See the substring docs.

Matthew Flaschen
Great! Thanks so much.
circey
+3  A: 
var $yoyo = window.location.hash.replace("#", "");

.remove() is a jQuery dom manipulation function. .replace() is a native javascript function that replaces a string with another string inside of a string. From W3Schools:

<script type="text/javascript">

var str="Visit Microsoft!";
document.write(str.replace("Microsoft", "W3Schools"));

</script>
Mike Sherov
+1 for explaining why .remove() doesn't work.
uncle brad
+2  A: 
$yoyo.substr(1)
Anurag