Does .onclick = function(){ (js) work when the item is clicked? I apologize for the stupid question, I just don’t want to later rewrite a very large part of the frontend.

  • one
    Why apologize for a stupid question, if you can simply not ask? - Igor
  • Delete the question and everything ... Right now, will fly 10 answers)))) - Air
  • Come on, he wrote with a dot, you never know what he meant. - Zicrael
  • @Zicrael, And what’s the point with it?))) - Air
  • And who knows where he puts it)) suddenly in html . - Zicrael

2 answers 2

Yes, it will work when you click on any element in principle, except that if another handler is registered to this element, then the behavior of your handler may be unpredictable (not always).

    It works like this:

     document.querySelector('div').onclick = function() { console.log('Я есть Div') } 
     <div> asd </div>