How do I find out the style of text by caret position in a contenteditable div?

  • 0
    I am making a simple WYSIWYG editor and there was a need to display the pressed button "B" (bold), which makes the selected text bold if the caret is in the tag limit (tags are not visible, because contenteditable). I don't want to reinvent the wheel, what if there is already an easier way to understand which tags contain the text by the position of the carriage?
    Here the caret position is the index not in the raw html, but in the rendered one - because that's the only one I still have. Actually, "index in raw" & lt; - & gt; "index in rendered" is another complication.
    JavaScript Anonymous, Aug 11, 2020

  • 1 Answers
  • 0
    I liked the puzzle.

    This is how you define the parent block of the selected text.

    My example

    AND stackoverflow
    Grace Hartman

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!