3 ms·
Sometimes you just need to do something the old way: let element = document.getElementById('some-element'); while (element) { // do something eleme
by Aldo_MX 10y ago
Sometimes you just need to do something the old way:
let element = document.getElementById('some-element');
while (element) {
// do something
element = element.parentElement;
}
let doesn't get in the way with behavior such as hoisting, and the code will break if you redeclare a variable.
- Roboprog 10y agoHow does var/hoisting get in the way of that, or at least, that particular, construct? FWIW, that would also be a nice "for" loop :-) var el for ( el = document.getElement... ; el ; el = el.parentElement ) { // do something }