---
title: "Discussion on \"HOW TO: Click outside to close in Javascript\" | Hashnode"
description: "Discussion on \"HOW TO: Click outside to close in Javascript\". How to close a modal or any context using HTML, CSS, and vanilla javascript by clicking outside"
url: "https://hashnode.com/posts/how-to-click-outside-to-close-in-javascript/61e659e0f6d40b3391ad6bfc"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [HOW TO: Click outside to close in Javascript](https://blog.charleskasasira.com/how-to-click-outside-to-close-in-javascript?utm_source=hashnode&utm_medium=feed)

How to close a modal or any context using HTML, CSS, and vanilla javascript by clicking outside

Jan 18, 2022 · 3 min read · blog.charleskasasira.com  
Updated Sep 22, 2022  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#html5](https://hashnode.com/tag/html5)
-   [#css](https://hashnode.com/tag/css)
-   [#click-outside-to-close](https://hashnode.com/tag/click-outside-to-close)

## Written by

[Charles Kasasira](https://hashnode.com/@Kasasira)

@Kasasira · Kampala, Uganda

  
[View profile](https://hashnode.com/@Kasasira)

Software engineer, aiming to design and develop experiences that make people’s lives simple

Software engineer, aiming to design and develop experiences that make people’s lives simple

## Responses 2

Markdown supported · ⌘↵ to post

[HUSSAIN AHMED](https://hashnode.com/@AHMEDHUSSAIN)

[Jan 19, 2022](https://hashnode.com/posts/how-to-click-outside-to-close-in-javascript/61e659e0f6d40b3391ad6bfc/comment/61e7c8496f4d6f431978c8e6)

It's a very helpful topic, Thanks for sharing, Like: [Illustrations.to](https://illustrations.to/)

[Charles Kasasira](https://hashnode.com/@Kasasira)

[Jan 20, 2022](https://hashnode.com/posts/how-to-click-outside-to-close-in-javascript/61e659e0f6d40b3391ad6bfc/comment/61e7c8496f4d6f431978c8e6#reply-61e94c3cb25efe60841c5b69)

Thanks **HUSSAIN AHMED**, glad you liked it. 💛

[GraceOS.](https://hashnode.com/@graceos)

[Jan 19, 2022](https://hashnode.com/posts/how-to-click-outside-to-close-in-javascript/61e659e0f6d40b3391ad6bfc/comment/61e7a5cd0204273bdcb10337)

Bookmarked. Thanks for sharing

[Charles Kasasira](https://hashnode.com/@Kasasira)

[Jan 20, 2022](https://hashnode.com/posts/how-to-click-outside-to-close-in-javascript/61e659e0f6d40b3391ad6bfc/comment/61e7a5cd0204273bdcb10337#reply-61e94b8cb25efe60841c5b50)

Thanks Grace, glad you liked it. 💛
