Try this:
document.body.onclick = function(e) {
var clickedEl = window.event ? event.srcElement : e.target;
while (clickedEl != null) {
if (clickedEl.className
&& (" " + clickedEl.className + " ").indexOf(" yourclass ") != -1) {
// do something, e.g.,
alert("Element with class was clicked");
return;
}
clickedEl = clickedEl.parentNode;
}
}
Demo: http://jsfiddle.net/3qChA/
This will do "something" (in my example show an alert) when any element with class "yourclass" is clicked, or when any descendant element of an element with "yourclass" is clicked. Obviously you can replace the hard-coded "yourclass" with a variable as appropriate.
myclasswhich is having some other class name, than it is not triggering.id. But i need that for class.