[whatwg] Intergrating the DOM and JavaScript (JSDOM)

Andrew Fedoniouk news at terrainformatica.com
Thu May 11 22:30:19 PDT 2006


----- Original Message ----- 
From: "Dean Edwards" <dean at 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













More information about the whatwg mailing list