About Document.querySelector() - Javascript and DOM


answer of this is:
const parent = document.querySelector("#more-destinations");
const child = document.querySelector("#oaxaca");

Can It be shortened the way this does:
var el = document.querySelector(“div.user-panel.main input[name=login]”);

If it is possible, can you tell me how to?
I tried to copy the form of it, but failed.

This is without context, so hard to discuss. The selector is rather specific, and perhaps unnecessarily so. From what we can tell, there is only one form control with the attribute name=login so that is specific enough for the selector.

In the case of this exercise, the id attributes are the simplest selectors.

A shorter form of solution would be,

var oaxaca = document.querySelector('#oaxaca');
1 Like

thank you for the answer!

looking at the shorter solution helped me understand some of the DOM stuff.

1 Like