If parent element has class, do something, in jQuery

JavaScript
// jQuery

What it does

Perform an action on click if its parent element has a specific class.

The Code

$(document).ready(function() {
    $("#childElement").click(function() {      
        if($(this).parent().hasClass("parentClass")) {
            // do something
        } else {
            // do something else
        }
    })
});

How To Use It

Paste this snippet into a JavaScript file that is loaded by your page, or you can put it between <script> </script> tags in the footer.

jQuery is required.

Menu