I want to get parentElement when I select some text in iframe.
iframe = document.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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.