开发者

Getting the parent element of the text near the cursor-Caret

开发者 https://www.devze.com 2022-12-14 00:52 出处:网络
For example: page has some paragraphs with text: <p>some text1</p> <p>some text2</p>

For example:

page has some paragraphs with text:

<p>some text1</p>
<p>some text2</p>
<p>some text3</p>

so the browser will render:

some text1

some text2

some text3

Now, if user places the Caret, lets say on text2 (between 't' and 'e' ,document is in designmode=on), the function should return ref to the second p object.

I think it should be done 开发者_运维技巧using range object...


You need to use the even of the editable box such as focus event and use the this keyword to get it's reference.


Have you considered adding onHover listeners to all the elements you might need to know if the mouse is over? Using jQuery (very basic example)

var currentHover = null;
$('p').hover(function(){
    currentHover = this;
},
function(){
    currentHover = null
});
0

精彩评论

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