...

View Full Version : changing style with Javascript (resolved)



pjleonhardt
09-22-2005, 07:18 AM
I'm trying to have an onClick event change the css properties of another element on my page.

In my CSS i have declared


div#extra {
visibility: hidden;
}




function showAdvanced()
{
document.getElementById("extra").style.visibility="visible";
}


is my function, I'm not sure if its right, I don't much experience with DOM, especially getElementById();

I have a sneaking suspicion the function isn't even being called though.

I call to it here:


<a href="" id="showAdvanced" onclick="showAdvanced();">Advanced &raquo;</a>


The problem is, when I click it, nothing happens.
Can you see the problem, or do you need more code?

Thanks.

_Aerospace_Eng_
09-22-2005, 07:50 AM
<a href="" id="showAdvanced" onclick="showAdvanced();return false">Advanced &raquo;</a>

pjleonhardt
09-22-2005, 07:55 AM
That didn't fix it, unfortunately. Though I figure it IS something as simple as that.

[:timelapse=30seconds:]

Okay, I figured it out. (Though, I prob. needed the return false as well.)

I had <script type="javascript">
instead of language="javascript"

to much CSS (type="text/css")

Thanks for you help, Paul

_Aerospace_Eng_
09-22-2005, 07:59 AM
The only real problem I saw was the return false which is good when you don't want the href to be activated. Because you had type="javascript" okay yes thats a problem. It should be type="text/javascript". language="javascript" is deprecated and shouldn't be used. The type declaration however should be used as it is required in order to validate.

pjleonhardt
09-22-2005, 08:10 AM
Excellent. Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum