开发者

How do I find out the DOM node when select text in a browser’s editable content window using Javascript?

开发者 https://www.devze.com 2022-12-23 19:15 出处:网络
I want to get parentElement when I select some text in iframe. iframe = d开发者_JS百科ocument.getElementById(\"iframe\");

I want to get parentElement when I select some text in iframe.

iframe = d开发者_JS百科ocument.getElementById("iframe");
function getParentElement(){
 var sel=iframe.contentDocument.getselection();
 return sel.parentElement()
}
getParentElement();

when I run this code it show Error:" TypeError: iframe.contentDocument.getSelection().parentElement is not a function { message="iframe.contentDocument....ement is not a function", more...}"

Please give me a help!


Selection object (returned by getSelection()) has no method named parentElement(). This will give you the parent:

getSelection().anchorNode.parentNode

See Mozilla's DOM reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消