• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Event Listener not working.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I'm having a problem with an event listener not being detected.
I've tried using "debugger; " to check through the developer tool what's happening, and I'm not really sure what I'm supposed to check specifically... Although I did check the event listener tab, and it isn't referencing anything from my code (as I have bootstraps, those are the only ones listed.) I also cannot really interact with the page, because the page I have has a buffer template, which prevents me from it. Because of this, I'm really stuck from debugging.

 
Saloon Keeper
Posts: 15617
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

The big strange thing that jumps out at me is that you're calling document.removeEventListener(), but instead of passing it a reference to an existing event handler, you are supplying it a new one using an anonymous function definition. Did you actually intend to call document.addEventListener() instead?

Because of this, it's hard for me to tell whether your problem is that the event listener that you add to calendarBody isn't working, or whether the problem is that the event listener that you're removing from document isn't working.

In the case that event handler that you're adding to calendarBody isn't working, doesn't it log anything to the console when you click the calendar body?

Note that your log message is misleading. It reads "Event listener added", but it won't actually be logged when you add the event listener. Instead, it will only be logged after you click the calendar body.

Please clarify the following:

  • What exactly did you expect to happen that isn't working?
  • Does your application log anything to console when you click the calendar body?
  • Did you intend to use removeEventListener() instead of addEventListener()?
  • Please share the relevant (and only the relevant) part of the HTML with us.
  • Could it be that another element is capturing events intended for the calendar body?
  •  
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You can use the toggle method on classlist to on / off a class on an element in js.

    Example.
    const button = document.querySelector("button")


    button.addEventListener("click", () => {
       button.classList.toggle("switchModalBox")
    })
     
    reply
      Bookmark Topic Watch Topic
    • New Topic