Home > Software design >  Creating and accessing unique html div via javascript
Creating and accessing unique html div via javascript

Time:12-08

Part of my script using the below to create the div.

days = <div >${i}</div>;

My question is how do I access it?

document.querySelector(".day8").addEventListener("click", () => {

Using this method works with other divs I have created but doesn't seem to work with divs inside divs... The structure is "day" inside of "days".

Sorry if this is not clear.

CodePudding user response:

This won't work if the div is created after you run the select script(document.querySelector(".day8").addEventListener("click", () => {).

The solution is that you will have to run the select script above once again after adding the div.

  • Related