开发者

Apply jquery css to contenteditable text selection

开发者 https://www.devze.com 2023-02-05 19:50 出处:网络
Can i apply css to selected text in a contenteditable div instead of using execcommand. For exmaple i would like to use jquery to apply css to a selected range such as $(savedRange).css({\'color\':\'r

Can i apply css to selected text in a contenteditable div instead of using execcommand. For exmaple i would like to use jquery to apply css to a selected range such as $(savedRange).css({'color':'red'}); But that does work. Can this be done.

I already have the saveselection and restoreselection functions working where i can save 开发者_JAVA百科and restore selected text. The variable savedRange is what contains the saved text.


You will need to wrap the selected text with a inline element (such as a span) and then style that element. You can try the wrap function. It would be hard to say for sure without having an example.

$(savedRange).wrap('<span />').css({'color':'red'});


How can I use jQuery to apply css to savedRange text selection?

0

精彩评论

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

关注公众号