0

I'm trying to detect when a modal opens so i can set the content height but simply does nothing.

Here's what I'm trying:

$('#bootModal').on('show', function () {
  alert('foo'); // doesn't fire
  $(this).find('.modal-body').css({
    'height':$( window ).height()*0.8
  });
});

Any ideas why it's not detecting the modal opening?

1
  • The event name is wrong?
    – geedubb
    Commented Sep 30, 2014 at 19:44

1 Answer 1

3

In Bootstrap 3, the event is shown.bs.modal not show

shown.bs.modal This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTarget property of the event.

http://getbootstrap.com/javascript/#modals

Sample: http://plnkr.co/edit/xp3GdIHF8rKLm8h6UhlL?p=preview

2
  • Changed show to shown.bs.modal but no difference, still not firing the alert or making a change to height
    – StudioTime
    Commented Sep 30, 2014 at 19:47
  • Hmmm - I just tried it within the JS file where I need it and it works too, many thanks for that. I had the function in a separate js file where i'd prefer it and I'm guessing it didn't read it because of that.
    – StudioTime
    Commented Sep 30, 2014 at 20:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.