Prefer .querySelector() over .getElementById(), .querySelectorAll() over .getElementsByClassName() and .getElementsByTagName() and .getElementsByName()
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§ This rule is automatically fixable by the --fix CLI option.
It's better to use the same method to query DOM elements. This helps keep consistency and it lends itself to future improvements (e.g. more specific selectors).
// β
document.getElementById('foo');
// β
document.querySelector('#foo');// β
document.getElementsByClassName('foo');
// β
document.querySelectorAll('.foo');// β
document.getElementsByClassName('foo bar');
// β
document.querySelectorAll('.foo.bar');// β
document.getElementsByTagName('main');
// β
document.querySelectorAll('main');// β
document.getElementsByClassName(fn());