Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if class is clicked javascript

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;
    }
}​
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #class #clicked #javascript
ADD COMMENT
Topic
Name
2+3 =