Solved

Bootstrap modal how to fire event on shown and hide

Posted on 2014-07-31
9
12,598 Views
Last Modified: 2014-08-14
Hi..
I'm using Bootstrap. I'm trying to fire an event when the modal 'window' is shown. but it never fire and don't get any errors. Any idea what's wrong with this?
thx

<!-- EDIT NOTES SECTION -->
<script>
    $('#editnote').on('hidden.bs.modal', function () {
        alert('hidden event fired!');
    });

    $('#editnote').on('shown.bs.modal', function () {
        alert('show event fired!');
    });
</script>

<div id="editnote" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
0
Comment
Question by:JElster
  • 5
  • 3
9 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40232263
How is the modal triggered? Attach the event to whatever element triggers it.
0
 
LVL 1

Author Comment

by:JElster
ID: 40232325
bootstrap js.. that know this is modal...  it's a link like this that is clicked - opens the modal window

<a href='#editnote' data-toggle='modal'
0
 
LVL 58

Accepted Solution

by:
Gary earned 480 total points
ID: 40232346
Where you bind the dialog you can add your own functions for open/close

$( "#editnote" ).dialog({
close: function( event, ui ) { // add your code here }
open: function( event, ui ) { // add your code here }
});

Open in new window

0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 1

Author Comment

by:JElster
ID: 40232403
I tried adding that.. doesn't do anything
nor this
   $('#editnote').on('shown.bs.modal', function () {
        alert('show event fired!');
    });
0
 
LVL 58

Expert Comment

by:Gary
ID: 40232434
Do you have a live link
Just double checked your original code locally and it works fine.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40232447
Where is the above script located? Is it at the end of the page?
If not you need to wrap it in a document ready function
0
 
LVL 1

Author Comment

by:JElster
ID: 40232483
Tried that.. still nothing and no JS errors..............?????????
0
 
LVL 58

Expert Comment

by:Gary
ID: 40232768
Post all your code.
0
 
LVL 43

Expert Comment

by:Rob
ID: 40233541
Hi JElster,

You're sure you've included jquery in your project? All these bootstrap plugins require it

http://getbootstrap.com/javascript/#js-individual-compiled

Cheers,

Rob
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question