Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click event not triggered on bootstrap modal

I am trying to catch the click event when save changes is pushed.

For some reason i can't catch the click event.

Why?

<script>
            $('#inviteRequest').click(function(){
//                e.preventDefault();
                console.log(1);
                $('#myModalInviteDestination').modal('hide');
            });

        </script>

        <!-- Modal -->
        <div class="modal fade" id="myModalInviteDestination" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Enter your friends email address</h4>
                    </div>
                    <div class="modal-body">
                        <textarea rows="5" cols="68" name="invites"></textarea>
                        <div>use ; as delimiter</div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" id="inviteRequest">Save changes</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
like image 806
Ionut Flavius Pogacian Avatar asked Nov 18 '13 12:11

Ionut Flavius Pogacian


2 Answers

You need to wrap this in a document.ready:

$(function() {
    $('#inviteRequest').click(function(){
        console.log(1);
        $('#myModalInviteDestination').modal('hide');
    });
});
like image 151
CodingIntrigue Avatar answered Sep 20 '22 04:09

CodingIntrigue


Use "live" which will bind the element when element will create

$('#inviteRequest').live('click',function(){
console.log(1);
$('#myModalInviteDestination').modal('hide');});
like image 23
Niraj NK Singh Avatar answered Sep 23 '22 04:09

Niraj NK Singh