How to addEventListener?

I tired differents ways to do this. But it keep send me an error, TypeError: Cannot read property ‘addEventListener’ of null.

var trythis = document.getElementById(‘trythis’);
function resetfilter() {
console.log(‘Did It!’);
}
trythis.addEventListener(“click”, resetfilter());

can anyone help? Thank you very much

Here is my site Read-Only: [LINK][1]
[1]: https://preview.webflow.com/preview/travelagain?utm_medium=preview_link&utm_source=designer&utm_content=travelagain&preview=4b10656a3ef46b97bc76a6a4dc044988&pageId=5f2fc7e94bc2982bbf26babe&mode=preview

1 Like

Anyone? Anyone? Need this for adding Google Pixel to a button click now. As suggested in your own page - Facebook Pixel | Webflow University - this sounds wrong. Found a Stackoverflow message addressing the issue, and it seems to run counter to your own recommendation.

So, who’s right? Why create a whole page with seemingly bad advice? Anyone?

this sounds wrong

Hi @rps which bit sounds wrong? If you can point me to the bit you’re having trouble with I can look into this more and get it updated where necessary.

As for the OP, don’t call the function in your eventListener, you should just add it as a reference… i.e
trythis.addEventListener(“click”, resetfilter());
should be
trythis.addEventListener(“click”, resetfilter);
Notice the parentheses are removed from resetFilter