Disable tr onclick event...

S

SomeGei

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?
 
M

Michael Winter

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 == 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top