I’m trying to make a firefox extension that will pop up a tooltip upon hovering over any text in a page. My first idea was to split the text on the page and wrap each word in a span tag and add an onMouseOver event handler to the spans. This doesn’t seem to be working: the onMouseOver property gets set, but the event handler isn’t fired. I inserted a normal span tag into the page and that fires the lookup function. Any help?
function lookup()
{
alert(“test”);
}
function addHover(node)
{
if(node.nodeType == 3 &&
node.nodeValue.length > 0)
{
var txt = node.nodeValue;
var words = txt.split(” “);
var j = 0;
var parent = node.parentNode;
var curChild = node;
for(j = words.length – 1; j >= 0; j–)
{
if(words[j].length > 0)
{
var span = document.createElement(“span”);
span.onMouseOver = “lookup()”
var newtxt = document.createTextNode(words[j]);
var newspc = document.createTextNode(” “);
span.appendChild(newtxt);
parent.insertBefore(newspc, curChild);
parent.insertBefore(span, newspc);
curChild = span;
}
}
parent.removeChild(node);
return;
}
var i = 0;
for(i = 0; i < node.childNodes.length; i++)
{
addHover(node.childNodes[i]);
}
}