views:

35

answers:

4

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?

+1  A: 

Window.location.hash="question"

JacobM
couldn't get it to work
Tony_Henrich
A: 
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;
});
Dmitri Farkov
A: 

Try:

<a href="javascript:SomeFunction();document.location='#question'">
RedFilter
+2  A: 

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>
Daniel Vandersluis
+1 for not using the pseudo-protocol javascript:
Residuum