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

<noob />
<noob />
16,621 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,838 Points

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

document.querySelector(".description");