Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close modal by clicking on background, but not on content

I have a modal that fadesIn and displays a video.

I'd like to click the modal's background color (which fills the screen 100%x100%) to close the modal. The problem is, the way I have it coded at the moment, if I click the video player controls, it closes the modal as well.

Fiddle here:

http://jsfiddle.net/PWGHH/

Thanks.

like image 822
Yahreen Avatar asked Aug 02 '11 18:08

Yahreen


People also ask

How do you prevent Bootstrap modal from hiding when clicked outside the content area?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

How do you close a modal by clicking outside?

You have two options to close this modal: Click on the "x" or click anywhere outside of the modal!

How do you automatically close modals?

Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Clicking on the modal “backdrop” will automatically close the modal.


1 Answers

Try this:

$('#commercial1').click(function(event) {
  event.stopPropagation();
});
like image 103
M. Cypher Avatar answered Sep 27 '22 16:09

M. Cypher