darkfreaks Posted April 21, 2009 Share Posted April 21, 2009 i need help hiding and matching tables. maybe i am doing it wrong since it dont work ??? t= document.getElementsByTagNames(); if(t.match("</table>") { display: none!important; } if(t.match("<table>") { display: none!important; } if(t.match("table") { display: none!important; } Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 22, 2009 Share Posted April 22, 2009 This code works, but it's not 100%. For some reason it has to be clicked twice the first time (which is unacceptable), but it will point you in the right direction. <script type="text/javascript"> function toggle() { var tables = document.getElementsByTagName('table'); for(var i = 0; i < tables.length; i++) { var x = tables[i]; x.style.display = (x.style.display == "block") ? x.style.display = "none" : x.style.display = "block"; } } </script> Quote Link to comment Share on other sites More sharing options...
markjoe Posted April 22, 2009 Share Posted April 22, 2009 I've always checked for display:none, and assumed anything else is visible. <script type="text/javascript"> function toggle() { var tables = document.getElementsByTagName('table'); for(var i = 0; i < tables.length; i++) { var x = tables[i]; x.style.display = (x.style.display == "none") ? x.style.display = "block" : x.style.display = "none"; } } </script> Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 22, 2009 Share Posted April 22, 2009 True, but my problem is that: for(var i = 0; i < tables.length; i++) { var x = tables[i]; x.style.display alert(x.style.display) will show a null value (empty alert) when I'm fairly certain it should show "block" or something. Quote Link to comment Share on other sites More sharing options...
markjoe Posted April 22, 2009 Share Posted April 22, 2009 The DOM isn't populated with default style properties. If you didn't set a style property, it will be null. I guess technically they are attributes, not properties, but whatever. Quote Link to comment 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.