I need some help, I want to basically do this for dynamically created elements (elements that were created after page loading), I cant figure it out on my own

```js
for (i=0;i<classname.length; i++){
    classname[i].onclick = function(){
    this.style.background = "red";
    };
}; 
or
 classname.forEach(element => {
        element.addEventListener("click", function(){

    })
});
```