0

I want to get an enter event on dynamically created div, What I'm trying to do is :

$('.emojionearea-editor').keypress(function(e){
    if(e.which == 13){//Enter key pressed
        alert('Enter pressed');
    }
});

but it's not working the way it has to, this div .emojionearea-editor is created on the run time and I'm not able to get it's enter event.

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
  • 4
    Possible duplicate of [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – Hikarunomemory Sep 14 '18 at 10:23
  • you can refer code from here https://stackoverflow.com/questions/52309011/how-to-make-checkbox-events-from-dynamically-created-checkbox-javascript/52309345#52309345 – Uttam Gupta Sep 14 '18 at 10:31

1 Answers1

0

Try this.

(function(){
  $(document).on('keypress', '.emojionearea-editor', function(e){
    if(e.which == 13){//Enter key pressed
        alert('Enter pressed');
    }
    });
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input class="emojionearea-editor">
Hao Yellow
  • 73
  • 1
  • 9