Solved

Bootstrap modal how to fire event on shown and hide

Posted on 2014-07-31
9
11,447 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
Comment Utility
How is the modal triggered? Attach the event to whatever element triggers it.
0
 
LVL 1

Author Comment

by:JElster
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:JElster
Comment Utility
I tried adding that.. doesn't do anything
nor this
   $('#editnote').on('shown.bs.modal', function () {
        alert('show event fired!');
    });
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 58

Expert Comment

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

Expert Comment

by:Gary
Comment Utility
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
Comment Utility
Tried that.. still nothing and no JS errors..............?????????
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Post all your code.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now