skip to Main Content
function select() {
  document.querySelector();
}

const modal = select('.modal');

modal.add.....

Why can’t I addEventListener for modal?

I try to change ‘querySelectorAll’ ,but it doesn’t work

2

Answers


  1. You don’t pass the query argument and you don’t return the element

    function select(query) {
      return document.querySelector(query);
    }
    
    Login or Signup to reply.
  2. It isn’t clear what you are selecting here. You are using a function called select and passing the argument ‘.modal’ but your function is not accepting any of parameters.
    So, the code must be

    function select(selector) {
      return document.querySelector(selector);
    }
    
    const modal = select('.modal');
    
    modal.add.....
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search