By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Javascript-triggered CSS "display" change

P: 11
Okay, I cannot figure this out. I have an external javascript file to declare variables and functions in my <head> element of my HTML. I've done this before and have made it work. And, likewise, studied my past suceeding brew and litterally copy and pasted the function but it still refuses to cooperate with me. What am I trying to do? I'll let the code do the talking:

Expand|Select|Wrap|Line Numbers
  1. function dispChange(eid){if(document.getElementById(eid).style.display=="none"){document.getElementById(eid).style.display="inline";}else{document.getElementById(eid).style.display="none";}}
that's my function. It makes 'eid's .style.display either "inline" or "none" appropriately, so I would have something like...

[HTML]<a href="javascript:dispChange('sNav')" class="dispTogg">...</a>[/HTML]

and there would be <span> element with the id 'sNav'. I'm completely stumped. hopefully thats enough info- this is my first question on here, so... yeah. that's that. Thanks for the help!
Apr 21 '08 #1
Share this Question
Share on Google+
2 Replies


P: 11
Okay, I cannot figure this out. I have an external javascript file to declare variables and functions in my <head> element of my HTML. I've done this before and have made it work. And, likewise, studied my past suceeding brew and litterally copy and pasted the function but it still refuses to cooperate with me. What am I trying to do? I'll let the code do the talking:

Expand|Select|Wrap|Line Numbers
  1. function dispChange(eid){if(document.getElementById(eid).style.display=="none"){document.getElementById(eid).style.display="inline";}else{document.getElementById(eid).style.display="none";}}
that's my function. It makes 'eid's .style.display either "inline" or "none" appropriately, so I would have something like...

[HTML]<a href="javascript:dispChange('sNav')" class="dispTogg">...</a>[/HTML]

and there would be <span> element with the id 'sNav'. I'm completely stumped. hopefully thats enough info- this is my first question on here, so... yeah. that's that. Thanks for the help!
Nevermind- I figured it out. When I called my JScript file I used "href" instead of "src".
Apr 21 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Glad to hear that you managed to solve it (and within the hour too!)

Just a note on links. Put the function call in an onclick and either make the href point to a real URL or just #:
[HTML]<a href="#" onclick="dispChange('sNav'); return false;" class="dispTogg">...</a>[/HTML]It doesn't change it much, but it's better to allow for JavaScript being disabled.
Apr 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.