Events on children of contenteditable element

后端 未结 3 1856
故里飘歌
故里飘歌 2021-01-19 17:05

I have

myDiv.bind(\'keypress\', \'> *\', function(event) { console.log(\'keypress\') });

but it does not seem to work.

myDiv is

3条回答
  •  天涯浪人
    2021-01-19 17:55

    Keypress event will bubble up to the container element, so you don't necessarily need bind to the children. Instead bind only to the container, than you can check which element was edited by accessing to the event.target property.

    $('#container').on('keypress', function (event) { alert(event.target) });
    

提交回复
热议问题