简体   繁体   中英

Click listener for button doesn't work in Bootstrap

I want to run some JavaScript code before modal window is shown, but when i click on button nothing happens and browser console doesn't give me any error.

jsfiddle

    <a href="#addEdgeModalB" class="btn"> EDGE </a>

<div id="addEdgeModal" class="modal hide fade">
  <div class="modal-body">
    <form class="form-horizontal">    
<div class="control-group">
    <div class="controls">
      <textarea rows="3"></textarea>
    </div>
  </div>


<script>
       $("#addEdgeModalB").on("click",function(e){
           alert("click");
           $("addEdgeModal").modal("show"); 
        });
</script>

Try,

$("[href='#addEdgeModalB']").on("click",function(e){
   alert("click");           
});

There is no id there for using id selector here. Use attribute equals selector at this context.

DEMO

Please refer to this for the correct modal markup.

DEMO

$("a.btn").on("click",function(e){
    alert("click");

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM