Topic: Need help - Javscript onclick event issue (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Topic: Need help - Javscript onclick event issue (Page 1 of 1)" rel="nofollow" >Topic: Need help - Javscript onclick event issue <span class="small">(Page 1 of 1)</span>\

Bipolar (III) Inmate

From: you tell me
Insane since: Mar 2004

IP logged posted posted 04-05-2008 15:08 Edit Quote

Hi guys need some help here pronto. I have a div whcih nests some other divs like this

<div id="container" onclick="dosomething()">
  <div id="column01">....</div>
  <div id="column02">....</div>
  <div id="column03">....</div>

The thing is that when I click on the container div - I've put in the onclick event of that div a function call to be executed. Now the thing is that lets say even if I click on any of the divs within the container i.e. column01, column02, column03 - it still fires the onclick event on the container div. I would like that if someone clicks on the divs column01 and divs column02 that the dosomething() function as described in the onclick event of the container div should NOT be executed... how do I do this?

Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 04-05-2008 17:13 Edit Quote

You have to check that the element that fired the event ( in the DOM2 standard, event.srcElement in non standards compliant browsers ) is element to which the event handler is attached ( event.currentTarget ).

onload = function()
	document.getElementById('container').onclick = function( event )
		var	event	= event||window.event,
			src	=||event.srcElement;
		if( src==event.currentTarget )
			//	hooray!

And forget about putting event listeneres inside the markup.


Post Reply
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
Your Text:
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu