Reputation: 55
i have a html like this
<a href="link.php" onClick="return false;">Click me</a>
$('a').click(function() {
var linked = "#"+$(this) .attr(href);
window.location=linked;
})
why this not working?
Upvotes: 0
Views: 150
Reputation: 68400
Change
var linked = "#"+$(this) .attr(href);
by
var linked = "#"+$(this).attr("href");
EDIT
Try with this
$('a').click(function(e) {
e.preventDefault();
var linked = "#"+$(this).prop("href");
window.location.hash = linked;
});
Upvotes: 2
Reputation: 4906
$('a').click( function( event ) {
location.href = '#' + $(this).attr( 'href' );
event.preventDefault();
event.stopPropagation(); // sometimes useful
return false; // sometimes useful
} );
you should supress the triggered event
Upvotes: 0
Reputation: 2922
I would get rid of the onClick="return false;"
part first and see what happens
Upvotes: 0
Reputation: 359776
If I understand what you're trying to do, you don't need JavaScript at all. Just change the href
:
<a href="#link.php">Click me</a>
Upvotes: 1