javascript rollover to get text

98 views Asked by At

Is it possible to use javascript in order when rolling over or (clicking) a word in a web page to get that word (e.g in variable). I would like to make a firefox extension with that feature.

2

There are 2 answers

1
ProllyGeek On BEST ANSWER

Ofcourse there is nothing such as clicking a word , as it is not an object , eventhough you can highlight a word , and yes you can get its value check this :

https://developer.mozilla.org/en-US/docs/Web/API/Window.getSelection

function foo() {
    var selObj = window.getSelection(); 
    alert(selObj);
    var selRange = selObj.getRangeAt(0);
    // do stuff with the range
}
1
Zero Fiber On

There is a HTML attribute which can use to get a tooltip on any element.

<p><abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>

Source: http://www.w3schools.com/tags/att_global_title.asp