By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Disable tr onclick event...

P: n/a
Hey guys....

i have a really big table... and the <tr> tags have onclick/onmouseover
events that highlight a row when you drag your mouse over it, and open a
popup window when you click anywhere in the row...

if i however have some text in the row that has an href link attached to it,
when i click on the link it will go to the href url AND open the popup
window...

is there any way to stop the popup window from opening when i click a
certain link within a row?
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 29 Aug 2004 17:27:32 GMT, SomeGei <so**@gei.com> wrote:
i have a really big table... and the <tr> tags have onclick/onmouseover
events that highlight a row when you drag your mouse over it, and open a
popup window when you click anywhere in the row...

if i however have some text in the row that has an href link attached to
it, when i click on the link it will go to the href url AND open the
popup window...

is there any way to stop the popup window from opening when i click a
certain link within a row?


Yes, but the approach depends on your environment. If you only care about
recent browsers, you can use the DOM (Document Object Model) to stop the
event propagating up the document tree. However, if you need to support
older browsers, it becomes much less elegant.

New browsers:

<a ... onclick="stopBubble(event);">

function stopBubble(e) {
if(e.stopPropagation) {e.stopPropagation();}
else {e.cancelBubble = true;}
}

See? Simple. :)

Old browsers:

<tr ... onclick="myFunction(event);">

<!-- Notice the difference in the call! -->

/* This is your pop-up code. */
function myFunction(e) {
var l = document.links,
i = l.length,
t = e.target || e.srcElement;

/* Search to see if the target element
* was a link. If it was, quit. */
while(i--) {if(l[i] == t) {return;}}

/* Rest of your function. */
}

By the way, I don't know how well the latter will work. It should be fine,
but I haven't tested it.

Good luck,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.