0

I am trying to add an onClick handler in insertAdjacentHTML method but getting SyntaxError: Function statements require a function name error, I have set a console log, it should show the console value but it throws the error,

Am I missing anything?

            document
              .querySelector(`[data-msgid="${view.id}"] .chat-msg__message`)
              ?.insertAdjacentHTML(
                'beforeend',
                `<div class="daisy-dropdown daisy-dropdown-end">
            <button tabindex="0" type="button">
              <i class="fa fa-bars ml-2"></i>
            </button>
            <div tabindex="0" class='${[
              'daisy-dropdown-content',
              'daisy-menu',
            ].join(' ')}'>
                <button onclick=${() => console.log('click')}>Kick</button>
            </div>
          </div>`              
);
  • Does this answer your question? [Attach event to dynamic elements in javascript](https://stackoverflow.com/questions/34896106/attach-event-to-dynamic-elements-in-javascript) – Ivar Jul 18 '22 at 14:29
  • @MattEllen I have added the closing parenthesis, by mistake the closing parenthesis was missed. – Anik Ahmed fathe Jul 18 '22 at 14:33

0 Answers0