开发者

get html and text of highlighted (selected) elements (spans) and store text in hidden textarea

I want to know how to get the html and text of spans that are selected. Example html:

<span>a</span>
<span>b</span>
<span>c</span>
<span>d</span>

so if I highlighted with my cursor (a-b)...I would get

var storedHtml 开发者_如何学JAVA=     `<span>a</span> <span>b</span>`
var text = "ab"

and the text would be stored in a hidden textarea


There's a few articles on this already:

  • Get the Highlighted/Selected text
    • Which references -> http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
  • Which in turn was a duplicate of: Selecting text in an element (akin to highlighting with your mouse)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜