Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if click is inside div javascript

var container = document.getElementsByClassName('container')[0];
document.addEventListener('click', function( event ) {
  if (container !== event.target && !container.contains(event.target)) {    
    console.log('clicking outside the div');
  }
});
Comment

javascript check if clicked inside div

// Get arbitrary element with id "my-element"
var myElementToCheckIfClicksAreInsideOf = document.querySelector('#my-element');
// Listen for click events on body
document.body.addEventListener('click', function (event) {
    if (myElementToCheckIfClicksAreInsideOf.contains(event.target)) {
        console.log('clicked inside');
    } else {
        console.log('clicked outside');
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-native how to get size of screen 
Javascript :: jquery remove first character from string 
Javascript :: random int between two numbers javascript 
Javascript :: js extract only numbers from string 
Javascript :: react native password input 
Javascript :: get string after character javascript 
Javascript :: how to edit a web page 
Javascript :: new MiniCssExtractPlugin({ ^ TypeError: MiniCssExtractPlugin is not a constructor 
Javascript :: how to console.log formData 
Javascript :: jquery cdn 
Javascript :: google hosted jquery 
Javascript :: dynamics 365 javascript set disabled 
Javascript :: textinput disable react native 
Javascript :: dynamics crm javascript set field visible 
Javascript :: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree 
Javascript :: get site url javascript 
Javascript :: jquery before form submit 
Javascript :: javascript clear div 
Javascript :: scroll jquery to anchor 
Javascript :: express req ip address 
Javascript :: fs renaming files 
Javascript :: socket io cdn 
Javascript :: invalid host header vue 
Javascript :: upgrade node version ubuntu 
Javascript :: npm create-react-app 
Javascript :: js scroll to top 
Javascript :: react toggle class 
Javascript :: jquery set title attribute 
Javascript :: javascript get scroll position 
Javascript :: react native scrollview horizontal 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =