Prefer .querySelector()
over .getElementById()
, .querySelectorAll()
over .getElementsByClassName()
and .getElementsByTagName()
✅ This rule is part of the recommended config.
🔧 This rule is auto-fixable.
It's better to use the same method to query DOM elements.
document.getElementById('foo');
document.getElementsByClassName('foo bar');
document.getElementsByTagName('main');
document.getElementsByClassName(fn());
document.querySelector('#foo');
document.querySelector('.bar');
document.querySelector('main #foo .bar');
document.querySelectorAll('.foo .bar');
document.querySelectorAll('li a');
document.querySelector('li').querySelectorAll('a');