1

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 and restore selected text. The variable savedRange is what contains the saved text.

Hussein
  • 42,480
  • 25
  • 113
  • 143

2 Answers2

0

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'});
Josiah Ruddell
  • 29,697
  • 8
  • 65
  • 67
  • This doesn't work on savedRanges. I will try to post a the code on jsfiddle so you can see what i mean. – Hussein Jan 19 '11 at 21:09
0

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

Community
  • 1
  • 1
Hussein
  • 42,480
  • 25
  • 113
  • 143