2

I had a div with links that underlined once you hover over them. I added an onmouseover JS event to the div and now the hyperlinks no longer underline when I hover over them, but instead whatever action I put into the onmouseover event gets executed instead.

CODE from function:

function addPlus(elementId)
{
 if(typeof addPlus.backup == 'undefined')
  addPlus.backup = document.getElementById(elementId).innerHTML;
 if(full)
 {
  document.getElementById(elementId).innerHTML = plusCode + addPlus.backup;
  return backup;
 }
 else
  return snippet;
}

div code:

<div class="nav_bar" id="navbar1" onmouseover="addPlus('navbar1')" onmouseout="removePlus('navbar1')">

EDIT: I've tried return true;, return Boolean(true);, and return new Boolean(true);, in an attempt to "return true" as Chad suggested. None of them work. Sorry, I really don't know what to do; I'm new to Javascript.

EDIT 2: Darn it, I just realized Chad meant that I return true in the div tag. So now I have <div class="nav_bar" id="navbar1" onmouseover="addPlus('navbar1');return true" onmouseout="removePlus('navbar1')">, but it unfortunately still doesn't work.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
wrongusername
  • 18,564
  • 40
  • 130
  • 214

3 Answers3

1

If you don't want for js event to fire you should stop event propogation when mouse enters <a>. Try adding onmouseover event handler for each hyperlink with return false - <a onmouseover="return false" ... - that should help.

Dmitriy
  • 2,742
  • 1
  • 17
  • 15
  • Isn't that the exact opposite of what chad suggested? It unfortunately still does not work :( I have ` – wrongusername Nov 23 '10 at 02:02
  • No, I suggested adding `return false` to links not `
    `. You shouldn't have `return` on `
    ` at all.
    – Dmitriy Nov 24 '10 at 07:24
  • oh! I'm sorry for my confusion; however, it seems like it still does not work :( – wrongusername Nov 24 '10 at 17:58
  • @wrongusername - if understood better what is desired effect I would be able to find better solution, but for now please check this out: http://jsfiddle.net/grassator/9NsVJ/3/ – Dmitriy Nov 25 '10 at 10:02
0

for the event to propagate you need to return true from your onmouseover handler.

chad
  • 2,888
  • 1
  • 17
  • 15
0
  1. This won't occur if you use CSS to underline your links instead of JavaScript
  2. You presumably have some rotten code that is explicitly setting an onmouseover handler in HTML or JavaScript to handle the link underline (instead of properly using addEventListener), and then you are overwriting this handler. It's hard to guess what might be wrong without more information. Supply a code example for more help.
Phrogz
  • 296,393
  • 112
  • 651
  • 745