-1

I want to write the following js code as jQuery:

JS

  document.getElementById("aa").addEventListener("paste", pasteHandler); 

  function pasteHandler(e){.....}

I tried something like that, but it did not work:

jQuery

$("#aa").addEventListener("paste", pasteHandler); 

  function pasteHandler(e){.....}
Jason P
  • 26,984
  • 3
  • 31
  • 45
user2952265
  • 1,590
  • 7
  • 21
  • 32

1 Answers1

7

Use on:

$("#aa").on("paste", pasteHandler);

.on( events [, selector ] [, data ], handler(eventObject) )

Description: Attach an event handler function for one or more events to the selected elements.

Also, you can access the DOM element using $("#aa")[0] and then:

$("#aa")[0].addEventListener("paste", pasteHandler);

But that's useless because you can use the built-in jQuery method.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474