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; } Link to comment https://forums.phpfreaks.com/topic/155109-solved-js-help/ 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> Link to comment https://forums.phpfreaks.com/topic/155109-solved-js-help/#findComment-816118 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> Link to comment https://forums.phpfreaks.com/topic/155109-solved-js-help/#findComment-816165 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. Link to comment https://forums.phpfreaks.com/topic/155109-solved-js-help/#findComment-816210 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. Link to comment https://forums.phpfreaks.com/topic/155109-solved-js-help/#findComment-816428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.