Skip to content
Sign upLog in
← Back to Community

Can’t get onclick attr to work

Profile icon
Giothecoder

in file public/index.html I use a div element with the onclick attribute to act as a button, but when I click on the button, nothing happens. It’s supposed to get rid of the button and the input element and then add a canvas element that covers the entire screen, but nothing happens. Anyone care to tell me what I’m doing wrong?

Thanks,
G

Update: I have found on the browser I’m using this warning:
[Violation] 'click' handler took <N>ms where is around 155 to 521. I don’t actually know if that’s any help, but yeah there you go.

Answered by eco27 [earned 5 cycles]
View Answer
Voters
Profile icon
Jacog28
Profile icon
Giothecoder
Comments
hotnewtop
Profile icon
eco27
  1. dont use onclick, use element.addEventListener in your javascript
  2. if you want a button, use a <button> not a <div>
Profile icon
Giothecoder

@MrEconomical

  1. Why?
  2. Aw..
Profile icon
eco27

@Giothecoder
its just better

Profile icon
Giothecoder

@MrEconomical

much confusion
How?

Profile icon
eco27

@Giothecoder
easier to debug I guess

Profile icon
Giothecoder

@MrEconomical
alright I’ll try it one sec...

Profile icon
Giothecoder

@MrEconomical
ok. So. Tried that. Now I’m not getting even a warning at all, so I think the problem isn’t with my click listening anymore, but with how I get the new element on the page, what do you think?

Edit: it has been fixed, sorry about not marking you as the answer, I forgot but there you go. Ty!