Is there a way to insert text similar to bbcode before and after the selected text in a contenteditable div? I've seen many answers for textarea, but the code does not work with a contenteditable div. IE support is not needed.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
The approach I'd suggest is:
The following demo will work in all major browsers except IE <= 8.
Demo: http://jsfiddle.net/8WEru/
Code:
If I understand from your comments the new goal, you have a selection and want to surround it by an element. Then the surroundContents method of range should work: