querySelector() vs getElementById()


#1

Which is preferred to use when I want to get an element?

document.querySelector('my-element');

or

document.getElementById('my-element');

When is one preferred over the other? What’s the difference between them?