Topic: Javascript/jQuery and/or PHP - get the value after the hash in a URL? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31312" title="Pages that link to Topic: Javascript/jQuery and/or PHP - get the value after the hash in a URL? (Page 1 of 1)" rel="nofollow" >Topic: Javascript/jQuery and/or PHP - get the value after the hash in a URL? <span class="small">(Page 1 of 1)</span>\

 
DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 09-15-2009 22:51

Hi all!

I have never had to think about this, and can't seem to figure out how to do it now...

I have a series of links to anchors within a number of pages, and the anchor name is an id number. I want to get that id so I can use jQuery to add a class to the list item in question and highlight the item for the user.

How can I get that value??

joksnet
Obsessive-Compulsive (I) Inmate

From: Aix-en-Provence, France
Insane since: Aug 2009

posted posted 09-15-2009 23:52

Hi, try:

code:
alert(location.hash);



Juan Manuel

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 09-23-2009 15:18

Thanks

That works great when linking between pages.
I have some that link to another anchor on the same page, and in that case, I can't get the current hash value with this method.

Any thoughts on how to get the correct value in that case?

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 09-23-2009 15:47

CSS only solution ( won't work in IE though ):

code:
#id:target
{
outline:2px solid solid;
}

No need for an extra class or whatever crazy thing.

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

posted posted 05-31-2011 11:04
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu