简体   繁体   中英

How can I get the text style from window.selection()?

I'm trying to get the css style of the text selection when user select only 1 row .

This is my code which works for multiple lines selection case:

var selectedDivs = window.selection().getRangeAt(0).cloneContent().children
// Then I can get css style from selectedDivs 

But for single line selection , the selectedDivs is always [] . How can I get the css style in this case? I've tried startContainer & endContainer of range but it didn't work.

startContainer parentNode应该为您提供所需的内容。

window.getSelection().getRangeAt(0).startContainer.parentNode

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM