Get element node at caret position (in contentEditable)
问题 Let's say I have some HTML code like this: <body contentEditable="true"> <h1>Some heading text here</h1> <p>Some text here</p> </body> Now the caret (the blinking cursor) is blinking inside the <h1> element, let's say in the word "|heading" . How can I get the element the caret is in with JavaScript? Here I would like to get node name: "h1" . This needs to work only in WebKit (it's embedded in an application). It should preferably also work for selections. 回答1: Firstly, think about why you're