Reputation: 44225
I have a hyperlink which goes to a named link. <a href="#question">
I needed it also to execute a Javascript so I did:
`<a href="javascript:SomeFunction();#question">`
which didn't work. I guess I have to jump to the named link from Javascript. How do I go to named link from Javascript?
Upvotes: 0
Views: 133
Reputation: 9691
window.location = "location here"
this will redirect to whatever url
EXAMPLE: window.location = "#header"
OR if using a framework like jQuery
$('a.cool').click(function(){
someFunction(this);
window.location = "#hash";
return false;
});
Upvotes: 1
Reputation: 94284
Put the named anchor in the href
and either use onclick
or register the event on the <a>
through javascript.
So either:
<a href="#question" onclick="SomeFunction();">
Or (this example makes use of prototype as an example, you could do the same with other javascript frameworks or with pure javascript):
<a href="#question" id="question_link">
<script type="text/javascript">
$('question_link').observe('click', SomeFunction);
</script>
Upvotes: 2
Reputation: 171559
Try:
<a href="javascript:SomeFunction();document.location='#question'">
Upvotes: 1