views:

142

answers:

1

I want to get the handle of the currently clicked link in jquery. Suppose, I have a bunch of li a elements:

HTML

<ul id="navigation" class="main_menu">
    <li><a href="#panel_home">Home</a></li>
    <li><a href="#panel_story">Story</a></li>
    <li><a href="#panel_mantra">Mantra</a></li>
    <li><a href="#panel_showcase">Showcase</a></li>
    <li><a href="#panel_experience">Experience Us</a></li>
</ul>

jquery

$(document).ready(function() {
    $("#navigation").localScroll({
        hash: false,
        onAfter: function(e, anchor, $target) {
            // some magic code here, to get the anchor element which was clicked
            // how do I use the 'e', 'anchor' and '$target' parameter to get the anchor?
        }
    }
});

If you could just alert() the anchor text or href, I'll be on my way...

Please note: I don't want to set hash: true for some reason.

A: 

You should just be able to add another click() event to the a elements. Is there a reason it needs to be done inside the localScroll()?

$('#navigation a').click(function() {
    alert($(this).attr('href'));
});

Or if you don't want the default behavior of clicking the a element, use the following:

$('#navigation a').click(function(event) {
    event.preventDefault();
    alert($(this).attr('href'));
});
patrick dw
yea..there is a reason. I want to capture that particular anchor element on which the user clicked and initiated the scroll. Once I get the anchor, I'll read it's href value and do further manipulation required to get the job done.
detj