How to select the currently clicked anchor element in jquery.localscroll?
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>开发者_StackOverflow社区</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.
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'));
});
精彩评论