Brav Posted May 18, 2010 Share Posted May 18, 2010 JS does not work in Firefox, but it works perfectly in all other browsers (IE, Opera, Chrome, Safari). Can someone tell me what seems to be the problem? Her is the code: <script type='text/javascript'>function hideShow(el_id){ var el=document.getElementById(el_id); if(el_id.style.display!="none"){ el_id.style.display="none"; }else{ el_id.style.display=""; } }</script> and code where i call on the function: ><a href="#" onclick="hideShow(rowA);">Hide/Show Row A</a> Link to comment Share on other sites More sharing options...
ShadowMage Posted May 18, 2010 Share Posted May 18, 2010 I believe we solved that in your other post. One other thing. Your function is a little off too. You have:function hideShow(el_id){ var el=document.getElementById(el_id); if(el_id.style.display!="none"){ el_id.style.display="none"; }else{ el_id.style.display=""; }} el is the reference to the element, el_id is the id used to get the reference. You should be access the properties of the element like this:el.style.display Link to comment Share on other sites More sharing options...
justsomeguy Posted May 18, 2010 Share Posted May 18, 2010 Javascript works just fine in Firefox. You're telling the browser to set the style.display property on a string, not an element. I would seriously doubt that code would work the way you want it to in any browser, in all browsers el_id will be a string ID of an element, not an actual element. Any browser I'm aware of will give an undefined property error on that if statement line. Link to comment Share on other sites More sharing options...
Brav Posted May 18, 2010 Author Share Posted May 18, 2010 jkloth changed it, but it still does not work. justsomeguy tried every other browser, everything works just fine. Error console says rowA is not defined - Line 1 - and this is highlighted <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">. Link to comment Share on other sites More sharing options...
ShadowMage Posted May 18, 2010 Share Posted May 18, 2010 and code where i call on the function:><a href="#" onclick="hideShow(rowA);">Hide/Show Row A</a> Error console says rowA is not defined - Line 1 - and this is highlighted <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">. We also solved that one.Also, when you pass the id to the function it needs to be surrounded by quotes:<a href="#" onclick="hideShow('rowA');"> Link to comment Share on other sites More sharing options...
Brav Posted May 18, 2010 Author Share Posted May 18, 2010 Hmmm, the stupidity of me Tnx for pointing that . Now it works. But one question. Why does it work in all other browsers, but it does not work in Firefox? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 18, 2010 Share Posted May 18, 2010 justsomeguy tried every other browser, everything works just fine.I find that hard to believe, but it may be that rowA in that context refers to the element with that ID. If you pass the ID as a string the way you normally would the function will not work in any browser. Link to comment Share on other sites More sharing options...
thescientist Posted May 18, 2010 Share Posted May 18, 2010 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.