开发者

Get multiple Span Tags inside the selection of Text in a HTML Page using JavaScript

I needed to get all the element ids within the selection range.

For example,

Start the work

If i selected the "Start" and "the" together i am only getting element id of "Start" using getelementbyselectionrange in开发者_如何学运维 javascript. How to get the array of span id's in the selection sentence.

I am trying this example in uiwebview in iphone, How to achieve this using javascript?

I got the jquery example in this site: http://jsfiddle.net/KC48j/17/ But it is not helping me?

Help me in this issue


Can you clarify "start the work". I'm not sure based on your description if the HTML of that sentence is:

<div id="d1"><span id="s1">start</span><span id="s2">the</span><span id="s3">work</span></div>

If that's the case, then you can use YUI's getElementsBy function in it's DOM package and make sure you specify the div id d1 as the root and the tag to be span. This will return back an array of span DOM elements within that div that you can loop on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜