Converting Range or DocumentFragment to string

前端 未结 6 1169
无人共我
无人共我 2021-02-05 03:07

Is there a way to get the html string of a JavaScript Range Object in W3C compliant browsers?

For example, let us say the user selects the following: Hello

6条回答
  •  爱一瞬间的悲伤
    2021-02-05 03:48

    Could DocumentFragment.textContent give you what you need?

    var frag = document.createRange().createContextualFragment("Hello World.");
    
    console.log(frag.textContent)

提交回复
热议问题