chiark / gitweb /
webstead: prefer querySelector[All] over getElement*
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 4 Oct 2025 21:27:37 +0000 (22:27 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 13 Jan 2026 21:42:18 +0000 (21:42 +0000)
It's a bit shorter, a bit more general, and allows me to properly
query only input elements that are children of the table of pixels.

webstead.xhtml

index c3bb0c1e5197142b193169413f2e7e28a69e3839..919d17ba515a61244873356df4d64523faaa9225 100644 (file)
@@ -46,9 +46,9 @@
     function update_glyph() {
         var args = [];
         var cstr = "";
-        for (var row of document.getElementById("pixels").rows) {
+        for (var row of document.querySelector('#pixels').rows) {
             var arg = 0;
-            for (var pixel of row.getElementsByTagName('input')) {
+            for (var pixel of row.querySelectorAll('input')) {
                 arg *= 2;
                 if (pixel.checked) {
                     arg += 1
@@ -75,7 +75,7 @@
         });
     }
     function init() {
-        for (var e of document.getElementsByTagName('input')) {
+        for (var e of document.querySelectorAll('#pixels input')) {
             e.onchange = update_glyph;
         }
         update_glyph();