Click outside element

Developer
Size
1,993 Kb
Views
42,504

How do I make an click outside element?

This is just a pen demonstrating how to catch mouse events outside element. . What is a click outside element? How do you make a click outside element? This script and codes were developed by Chrysto on 16 July 2022, Saturday.

Click outside element Previews

Click outside element - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Click outside element</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p class="log">You clicked on: </p>
<div class="box"> Click me <p>nested p</p>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Click outside element - Script Codes CSS Codes

body, div, p{ margin:0;	padding:0;
}
body {	background-color:#d6d6d6;
}
.log {	position:relative;	top:10px;	left:10px;	color:#000;
}
.box {	position:relative;	top:50px;	left:100px;	width:100px;	height:100px; font-size: 18px; text-align: center; color: white;	background-color:#79abff;
} .box p{ color: black; }

Click outside element - Script Codes JS Codes

$(function(){	var $win = $(window); // or $box parent container	var $box = $(".box");	var $log = $(".log"); $win.on("click.Bst", function(event){	if ( $box.has(event.target).length == 0 //checks if descendants of $box was clicked && !$box.is(event.target) //checks if the $box itself was clicked ){	$log.text("you clicked outside the box");	} else {	$log.text("you clicked inside the box");	}	});
});
Click outside element - Script Codes
Click outside element - Script Codes
Home Page Home
Developer Chrysto
Username bassta
Uploaded July 16, 2022
Rating 3
Size 1,993 Kb
Views 42,504
Do you need developer help for Click outside element?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Chrysto (bassta) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!