Site icon Anthony Carbon

Jquery on click inside or outside the div element

How to solve Jquery on click inside or outside the div element ? Just copy the codes below to your script.

$( document ).click( function( e ){
    var mde = $( '.my-div-element' );
    if( ! mde.is( e.target ) && mde.has( e.target ).length === 0 && mde.length ){ 
        // I'm clicking outside of my div element
    }else{
    	// I'm clicking inside of my div element
    }
});
Exit mobile version