W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2006

[whatwg] Intergrating the DOM and JavaScript (JSDOM)

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Thu, 11 May 2006 22:30:19 -0700
Message-ID: <001301c67585$285e32c0$3401a8c0@TERRA>
----- 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

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:27 UTC