Topic: Need help - Javscript onclick event issue (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=30173" 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>\

 
paritycheck
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

code:
<div id="container" onclick="dosomething()">
  <div id="column01">....</div>
  <div id="column02">....</div>
  <div id="column03">....</div>
</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?

poi
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 ( event.target in the DOM2 standard, event.srcElement in non standards compliant browsers ) is element to which the event handler is attached ( event.currentTarget ).

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

And forget about putting event listeneres inside the markup.

HTH



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

« BackwardsOnwards »

Show Forum Drop Down Menu