user3155063
user3155063

Reputation: 13

Calling a javascript and opening a link

I want to call a javascript and jump to a specified div by clicking on Text. Here is the javascript I am using:

function hide(parameter) {
    document.getElementById(parameter).style.visibility = "hidden"
}

and here the text that should call it:

<a id="text" href="Page.html#foo" href="javascript: hide('text')">Text Text</a>

I just don't know why it doesn't work.

Upvotes: 0

Views: 58

Answers (2)

markasoftware
markasoftware

Reputation: 12652

@user3155154's answer is the "best" way to do it, but, if you're interested, this will work too:

<a id="text" href="javascript:hide('text');window.location.href='Page.html#foo';void(0)">Text Text</a>

Upvotes: 0

Nitek
Nitek

Reputation: 2614

You cannot add a second href attribute to your a tag. Try onclick instead:

<a id="text" href="Page.html#foo" onclick="hide('text')">Text Text</a>

Upvotes: 4

Related Questions