kn0wl3dg3 Posted January 10, 2011 Share Posted January 10, 2011 Hoping you guys can help... I've got this html: <h3 onclick="change('screens')" class="clickable">Biometric Screenings</h3> <ul id="screens"> <li>List item number 1</li> <li>List item number 2</li> <li>List item number 3</li> </ul> And this javascript function: function change(id) { if (document.getElementById(id).style.display=='none') { document.getElementById(id).style.display='block'; } else { document.getElementById(id).style.display='none'; } } This is the css: #screens { display:none; } This is just a header that will show a list when clicked on...very simple. This works just fine except it requires an extra click before it will operate and then it works normally until you refresh/leave. Any ideas why that is and how to get rid of it? Quote Link to comment https://forums.phpfreaks.com/topic/223972-function-needs-extra-click-to-start/ Share on other sites More sharing options...
brianlange Posted January 10, 2011 Share Posted January 10, 2011 If you add an inline style to the ul it will work. I'm not sure why the javascript can't pick up the display property from the css declaration. <ul id="screens" style="display: none;"> <li>List item number 1</li> <li>List item number 2</li> <li>List item number 3</li> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/223972-function-needs-extra-click-to-start/#findComment-1157445 Share on other sites More sharing options...
kn0wl3dg3 Posted January 10, 2011 Author Share Posted January 10, 2011 If you add an inline style to the ul it will work. I'm not sure why the javascript can't pick up the display property from the css declaration. <ul id="screens" style="display: none;"> <li>List item number 1</li> <li>List item number 2</li> <li>List item number 3</li> </ul> Thanks for the response! Sorry, maybe I was unclear about my exact issue...it does work, but I have to click once on it before it will work (so i click, then click again and it works) I'll try what you suggested though...right after lunch Quote Link to comment https://forums.phpfreaks.com/topic/223972-function-needs-extra-click-to-start/#findComment-1157455 Share on other sites More sharing options...
kn0wl3dg3 Posted January 10, 2011 Author Share Posted January 10, 2011 If you add an inline style to the ul it will work. I'm not sure why the javascript can't pick up the display property from the css declaration. <ul id="screens" style="display: none;"> <li>List item number 1</li> <li>List item number 2</li> <li>List item number 3</li> </ul> My mistake, you were right, I guess I was misunderstanding. Strange as it is, that seemed to take care of the extra click...thank you very much!! Now my question becomes: why is it doing that/how do I fix it so it will grab from the css file easier? I'd rather not define it inline if I can avoid it. Thanks again brianlange Quote Link to comment https://forums.phpfreaks.com/topic/223972-function-needs-extra-click-to-start/#findComment-1157474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.