JavaScript JavaScript and the DOM Making Changes to the DOM Creating New DOM Elements

status 401
status 401
14,194 Points

question about querySelector

evreytime i use querySelector to get an access to an input or a button i need to first name the kind of the thing and then the class name?

for exmaple:

const descriptionButton = document.querySelector("button.description");
const addItemInput = document.querySelector("input.addItemInput");
const addItemButton = document.querySelector("button.addItemButton");
const descriptionP = document.querySelector("p.description");

u see?, lets take the descriptionButton for example. he has a class name "description" and to access it we do button.description why we cant for exmaple query this by using getElementbyClassName("description")?

1 Answer

Adam Pengh
Adam Pengh
28,635 Points

You can use querySelector with just the class .description, but you need the period to indicate it is a class selector