I have two divs, a big one and a smaller over the other, each div has its own OnClick method. The problem I have is when I clicked the smaller div, the big div\'s OnClick me
The best way to detect which element was clicked is to analyze target of event ( click event ). I have prepared small example for this case. You can see it in code below.
function amIclicked(e, element)
{
e = e || event;
var target = e.target || e.srcElement;
if(target.id==element.id)
return true;
else
return false;
}
function oneClick(event, element)
{
if(amIclicked(event, element))
{
alert('One is clicked');
}
}
function twoClick(event, element)
{
if(amIclicked(event, element))
{
alert('Two is clicked');
}
}
This javascript method can be called before you execute your script
Example
onetwo
I hope this helps.