3 ms·
Is there a way to make this also work as a function? e.g. myTable.$$('tr').foreach()
by crtasm 3y ago
Is there a way to make this also work as a function? e.g. myTable.$$('tr').foreach()
- mg 3y agoimport {qsA} from './dqs.js'; rows = qsA(myTable, 'tr');
- crtasm 3y agoThanks but the point is being able to chain it: myTable.qsA('tr') TypeError: myTable.qsA is not a function
- mg 3y agoWell, since html elements already have a querySelectorAll function, you could just assign it to a new method "qsA": HTMLElement.prototype.qsA = HTMLElement.prototype.querySelectorAll; Now myTable.qsA('tr') will work. You can try it right here on the HN page in the browser console: HTMLElement.prototype.qsA = HTMLElement.prototype.querySelectorAll; document.querySelector('#hnmain').qsA('tr'); Why do you prefer chaining?