Skip to content Skip to sidebar Skip to footer

Hhow To Get Caret Position For Contenteditable Div?

I am making a text editor for my blogging website. I want to give users a small tool box where they could edit their blog post by selecting the text and applying some styling, like

Solution 1:

The jQuery caret plug-in (I assume you mean this one) is only for text inputs and textareas. Contenteditable elements work very differently, so that's why it isn't working.

If you want the caret position or selection in terms of character offsets, my answer here may help, although generally for what it sounds like you're trying to do, these numbers won't be very helpful. It sounds to me as though you need to be looking at document.execCommand().

Post a Comment for "Hhow To Get Caret Position For Contenteditable Div?"