Team:Freiburg/Project/toolkit
From 2013.igem.org
(Difference between revisions)
Line 10: | Line 10: | ||
############################################################################## --> | ############################################################################## --> | ||
- | <script | + | <script type="text/javascript"> |
- | function | + | if (document.getElementsByClassName == undefined) { |
- | + | // only needed for old browsers like IE8 and earlier | |
- | for(i = 0; i < | + | // http://www.snipplr.com/view/45280/getelementsbyclassname/ |
- | + | document.getElementsByClassName = function(className, node) { | |
- | + | if(!node) node = document.getElementsByTagName("body")[0]; | |
- | + | var a = []; | |
- | + | var re = new RegExp('\\b' + className + '\\b'); | |
- | + | var els = node.getElementsByTagName("*"); | |
- | + | for(var i=0,j=els.length; i<j; i++) | |
- | + | if(re.test(els[i].className))a.push(els[i]); | |
- | + | return a; | |
+ | } | ||
+ | } | ||
+ | |||
+ | function toggle(theClass, display) { | ||
+ | var elems = document.getElementsByClassName(theClass); | ||
+ | var state = document.getElementById("state"); | ||
+ | for (var i=0; i<elems.length; i++) | ||
+ | elems[i].style.display = display; | ||
+ | if (display == "block") | ||
+ | state.innerHTML = "All Descriptions Shown"; | ||
+ | else state.innerHTML = "Classed Descriptions Hidden"; | ||
+ | } | ||
+ | |||
+ | document.getElementById("cbox").onclick = function() { | ||
+ | if (this.checked) toggle("descr", "block"); | ||
+ | else toggle("descr", "none"); | ||
} | } | ||
</script> | </script> | ||
Line 83: | Line 99: | ||
<form> | <form> | ||
- | <input type="checkbox" | + | <fieldset> |
+ | <label for="cbox" id="state">All Descriptions Shown</label> | ||
+ | <input id="cbox" type="checkbox" checked="checked" /> | ||
+ | </fieldset> | ||
</form> | </form> | ||
- | + | <ul> | |
- | < | + | <li class="descr">Hello This is #1 (can be toggled)</li> |
- | + | <li class="descr">Hello This is #2 (can be toggled)</li> | |
- | < | + | <li class="descr">Hello This is #3 (can be toggled)</li> |
- | + | <li>Hello This is #4 (cannot be toggled)</li> | |
- | </ | + | </ul> |
Revision as of 21:55, 17 September 2013
- Hello This is #1 (can be toggled)
- Hello This is #2 (can be toggled)
- Hello This is #3 (can be toggled)
- Hello This is #4 (cannot be toggled)