contentEditable cursor's parent element

后端 未结 1 573
天涯浪人
天涯浪人 2021-01-21 12:01

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

相关标签:
1条回答
  • 2021-01-21 12:19

    Example using parentNode:

    document.getElementById('editable').onclick = function () {
     alert(this.parentNode.id);   
    }
    
    0 讨论(0)
提交回复
热议问题