1

$('#head_menu a').click(function(){ currentPage = document.location.hash.split('#')[1]; });

<div id="head_menu">
    <a href="#order"><div>make order</div></a>
    <a href="#portfolio"><div>portfolie</div></a>
    <a href="#contacts"><div>contacts</div></a>
    <a href="#vacancies"><div>vacancies</div></a>
    <a href="#about"><div>about company</div></a>
</div>

So, when I'm clicking to the links in head_menu div I come into this handler. But one trouble: if url has, for example, #about hash, in handler I'll get 'about', not that, at what I've clicked. Could I get new url-hash in click-handler?

2 Answers 2

2

Why not just look at the href attribute of the link that was clicked?

$('#head_menu a').click(function(){
   currentPage = this.href.split('#')[1];
});
Sign up to request clarification or add additional context in comments.

1 Comment

you could also get the hash from the attribute... $(this).attr('hash'); but this includes the hash (#) as well.. this is nice sometimes if you need the hash for an ID somewhere on your page :P
2

Don't understand question ;)

BTW:

Another person who insert div into a. "a" is inline element so it couldn't has Div (it is block elemennt)

1 Comment

Not true for HTML5 any more, a can wrap div and other block level elements: davidwalsh.name/html5-elements-links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.