skip to Main Content

Html – How to add id to each element in this case?

Given this code: var words=['ac', 'bd', 'bf','uy','ca']; document.getElementById("wordTable").innerHTML=arr2tbl(2); function arr2tbl(ncols){ return words.reduce((a,c,i)=>{ if(i%ncols==0)a.push([]); a.at(-1).push(c); return a; },[]).map(r=>"<tr>"+r.map(c=>`<td>${c}</td>`).join("")+"</tr>").join("n"); } <table id="wordTable"></table> the code prints out this table <table> <tr> <td>ac</td> <td>bd</td> </tr> <tr> <td>bf</td> <td>uy</td> </tr> <tr> <td>ca</td><td></td> </tr> </table> But…

VIEW QUESTION

Detect caps lock in HTML input element

I want to detect CapsLock in an input. I used getModifierState which I found here: function handle(ev, el) { //if (ev.isComposing || ev.keyCode === 229) return; // for firefox let isCapsLockOn = ev.getModifierState('CapsLock'); document.getElementById('message').innerText = isCapsLockOn ? 'CAPS LOCK' :…

VIEW QUESTION
Back To Top
Search