Search code examples
javascripthtmlcontenteditablecursor-position

contentEditable cursor's parent element


I have a contentEditable HTML element. I would like to get the cursor's parent element. For example, if the cursor is inside a table cell, I would like to display some controls for editing the table. Is this possible? Or am I going to track all key and mousepresses?


Solution

  • Example using parentNode:

    document.getElementById('editable').onclick = function () {
     alert(this.parentNode.id);   
    }