How can I blur a div where contentEditable=true?

前端 未结 4 881
逝去的感伤
逝去的感伤 2021-01-11 08:57

How can I blur/focusout a div where contentEditable=true? I have attempted $(elm).blur() and $(elm).attr(\'contentEditable\', false);

4条回答
  •  迷失自我
    2021-01-11 09:55

    The suggested solution by Roman Resh doesn't work when you click into the element and hit enter immediately after. It won't blur but create line-breaks/divs.

    It is possible to prevent this behaviour entirely.

    See this fiddle

    $('

    ') .appendTo('body').focus().remove();

提交回复
热议问题