- From: Andrew Fedoniouk <news@terrainformatica.com>
- Date: Thu, 11 May 2006 22:30:19 -0700
----- Original Message ----- From: "Dean Edwards" <dean@edwards.name> To: "whatwg" <whatwg at whatwg.org> > Some code to illustrate: > > // old way > var isChecked = false; > var inputs = document.getElementsByTagName("input"); > for (var i = 0; i < inputs.length; i++) { > if (inputs[i].type == "checkbox" && inputs[i].checked) { > isChecked = true; > break; > } > } > > // better (using iterators on NodeList) > var isChecked = > document.getElementsByTagName("input").some(function(input) { > return input.type == "checkbox" && input.checked; > }); > > // even better (using W3C Selectors API) > var isChecked = > document.matchAll("input[type=checkbox]").some(function(checkbox) { > return checkbox.checked; > }); > This is in fact just one line: var checked = root.select("input[type=checkbox]:checked"); --------- Experimental JSDOM implementation: http://www.terrainformatica.com/sciter/Element.whtm if someone interested. Real life "behavior" is here: http://www.terrainformatica.com/codelib/view.php?sid=1 (and in Sciter demo) it transforms <table> into browsable "grid": http://www.terrainformatica.com/htmlayout/images/grid1.jpg Andrew Fedoniouk. http://terrainformatica.com
Received on Thursday, 11 May 2006 22:30:19 UTC