Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript event handler executes twice

 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a DIV element in my html page and an image inside the DIV element
as given below


both elements have a onclick event but I want to execute only method "b()" in case the user clicks on the image.Now both a() & b() are executed sequentialy becasue div is the container of the image
do you have any idea how to block execution of a() if the user clicks on the image.
[ August 31, 2005: Message edited by: Anoop Krishnan ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want a() to execute, why don't you just remove that onclick handler in the div tag?
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I should have added more details the same div contains a string too so if the user clicks on the string a() must be executed and if the user clicks on the image b() must be executed.
SO I can not leave out the invocation of a()
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I should have added more details the same div contains a string too so if the user clicks on the string a() must be executed and if the user clicks on the image b() must be executed.
SO I can not leave out the invocation of a()
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, why don't you put the string into its own SPAN, and then you can add the event handler to that, instead of putting it into the parent DIV.
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok then I have to explain it more
this is the structure


Now I want to allow the user to click anywhere on the entire 200px width
to trigger a() but if he click on the image only b() must be executed
I think this explains more details about the problem
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, something like the following should do the trick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic