window.getSelection() gives me the selected text, but I want the HTML

后端 未结 3 1274
逝去的感伤
逝去的感伤 2020-11-28 22:18

I\'m extending a WYSIWYG HTML editor (for Firefox), I want to add tags around a selection. I can\'t find a function to accomplish this in the Mozilla Midas specification.

3条回答
  •  再見小時候
    2020-11-28 23:02

    window.getSelection() will return an object. You can use the returned selection object as a string by calling the objects .toString() method.

    var selObj = window.getSelection();
    var selectedText = selObj.toString(); 
    

    https://developer.mozilla.org/en/DOM/window.getSelection

提交回复
热议问题