0

I'm using Twitter Bootstrap modal. When the modal is opened, it adds a class '.modal-open' to the body. When it closes, it removes this class.

I'm trying to identify when the body element has this class, but it doesn't work:

$(document).ready(function() {

if($('body').hasClass('modal-open')) {
    console.log('open');
} else {
    console.log('closed');
}       

});


<img src="img/projects/kitty.jpg" width="100%" height: "auto" data-toggle="modal" data-target=".kitty_modal">

When click the image, it shows modal. The code that makes the modal open is from bootstrap. I just want to remove overflow when the class 'modal-open' is added, so I can scroll the modal.

Ana Claudia
  • 487
  • 5
  • 15

1 Answers1

-1

Maybe something like this? I think you are missing a #.

<script>
$(document).ready(function ()
{

    if ($('#body').hasClass('modal-open'))
    {
        alert("modal open");

    } else
    {
        alert("modal closed");

    }

});
</script>