Search code examples
javascriptjquerydomcontenteditable

Replace JQuery for contenteditable element event binding


I'm using JQuery in my project, and the only line it gets used is the following:

$('#div').on('input', function() { ... });

Is there a more lightweight lib/polyfill I can use instead, which allows to register an input event on a contenteditable div?


Solution

  • In pure javascript you can do something likes that :

    document
       .getElementsByTagName("div")
       .addEventListener('input', function() { ... }));
    

    And add this html attribute contenteditable="true" on your div.