Set focus on div contenteditable element

后端 未结 9 2121
深忆病人
深忆病人 2020-11-29 01:51

I have a

where I define by a WYSIWYG some elements. For example

,

, etc. I would l

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 02:11

    Bind a "click" event handler to all elements within the contenteditable div, and change the class/style on click (i.e. add class "focused" to the element);

    You can identify, to the user, which element has focus by adding style such as a colorful border or an inner box-shadow. Then when you want to access the focused element in your jQuery script, just do something like this:

    var focused = $('.focused');

提交回复
热议问题