Prevent Chrome from wrapping contents of joined

with a

后端 未结 8 1664
情歌与酒
情歌与酒 2021-02-01 16:00

I have observed an undesirable behaviour in Chrome that occurs when one joins two

\'s by deleting the separation between them. Although the

8条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 16:03

    Here is my take on removing the extra spans

    document.querySelector('[contenteditable=true]')
      .addEventListener('DOMNodeInserted', function(event) {
        if (event.target.tagName == 'SPAN') {
          event.target.outerHTML = event.target.innerHTML;
        }
      });
    

提交回复
热议问题