Matt
Matt

Reputation: 8942

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>

Upvotes: 1

Views: 727

Answers (2)

PeterKA
PeterKA

Reputation: 24638

Please refer to this for the correct modal markup.

DEMO

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

});

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

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

Upvotes: 2

Related Questions