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 -->

Answers

You need to wrap this in a document.ready:

$(function() {
$('#inviteRequest').click(function(){
console.log(1);
$('#myModalInviteDestination').modal('hide');
});
});
Your element #inviteRequest does not exist at the time you try to add an event handler to it. You need to wait for the page to load first. My code is the equivalent to $(document).ready(); 

最新文章

  1. django系列--第一节
  2. Moon.Orm 5.0(MQL版)分页功能的设计(求指教,邀请您的加入)
  3. ARP协议工作流程
  4. awk系列:在awk中如何使用流程控制语句
  5. SQL Server 2012将数据库备份到网络中的共享文件夹
  6. Hadoop build error java.lang.NoClassDefFoundError: org/sonatype/aether/graph/DependencyFilter
  7. mysql数据库管理备份运维常用命令
  8. html5 中常用的标签和属性
  9. ajax用户名校验demo详解
  10. PHP根据经纬度,计算2点之间的距离的2种方法
  11. final的深入理解 - final数据
  12. wireshark 过滤条件汇总
  13. js与DOM初步:访问html元素
  14. java8-Stream之数值流
  15. 流式大数据计算实践(3)----高可用的Hadoop集群
  16. iOS开发基础-UITableView控件简单介绍
  17. js中的回调函数 和promise解决异步操作中的回调地狱问题。
  18. Linux的基础命令, django的安装与使用
  19. [原][OSG]OSG例子程序简介
  20. 天地图常用WMTS配置参数

热门文章

  1. (十八)python 3 回调函数
  2. NGINX模块(一)
  3. xtu summer individual 2 E - Double Profiles
  4. python002 Python3 基础语法
  5. Flask--登录检查(简单篇)---xunfeng巡风实例篇
  6. 让你的 CDN 费用省 50% 以上!图片瘦身的正确姿势
  7. CodeForces 444C 节点更新求变化值的和
  8. 【判连通】HDU 6113 度度熊的01世界
  9. [Vijos] SuperBrother打鼹鼠
  10. python学习之-- assert断言