Article From:https://segmentfault.com/q/1010000009897336
Question:

The rich text editor uses nicEditor, and there are many elements in the edit area. How do you get the node where ‘Hi’ is located?

Answer 0:

Similar to the fontSize command, add the font element of face=id, and then locate the current element through this ID:

var id="execCommandTest"
document.execCommand('fontName',null,id)
$(elem).find("font[face='"+id+"']") 
document.execCommand('undo',null)//After taking the element to remove the mark, there is no trace.

demo:

<div contenteditable="true">
        44444444
    </div>
    <button type="button" >click</button>
    <script type="text/javascript">
        $("button").click(function(){
            var id="execCommandTest"
            document.execCommand('fontName',null,id)
            console.log($('div').find("font[face='"+id+"']").html())

            document.execCommand('undo',null)        
        })
    </script>  

Effect:

Answer 1:

![

Picture description][1]