1

How do I add a bootstrap modal in the the javascipt on click. So far I was only able to alert ("hello") on click. How do i prompt out a modal box?

 graph.on("click", function (params) {
       var node = params['nodes'][0];
       displayInfo=false;
       if(node!=null){
        console.log('node:'+ params['nodes'][0]);
         x = params["pointer"]['canvas']['x'];
         y = params["pointer"]['canvas']['y'];   

         displayInfo=true;
         lastNode = nodes.get(node);
         lastClick = params['pointer'];
         //console.log(node);   
       }
       alert("hello");

       //add boostrap modal here    
     });
RSS
  • 23
  • 8
stackoverflow
  • 19
  • 1
  • 6
  • Possible duplicate of [Bootstrap modals: how to open with onClick=""](http://stackoverflow.com/questions/20111219/bootstrap-modals-how-to-open-with-onclick) – jarvo69 Sep 24 '16 at 06:09

4 Answers4

0

You don't need an onclick.

<div class="span4 proj-div" data-toggle="modal" data-target="#GSCCModal">Clickable content, graphics, whatever</div>

<div id="GSCCModal" class="modal fade" 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">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

If you need an onclick event anyhow, use it like below:

    graph.on("click", function (params) {
$('#myModal').modal('show');
}

Reference: http://getbootstrap.com/javascript/#modals

jarvo69
  • 7,908
  • 2
  • 18
  • 28
0
Amr Magdy
  • 1,710
  • 11
  • 13
0

You can use id like

$("#modal-id").modal("show");

Or you can use class name $(".modal-class").modal("show");

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
0

First make the modal pop up div then , Configure and use .modal('show') For eg:-

 <a href="" data-target="#modalDiv" data-toggle="modal"> You can also use onClick call for jquery here.  </a>
  <div id="modalDiv">
       //some content
  </div>

In jquery use ,

     $("#modalDiv").modal('show');

Check this http://getbootstrap.com/javascript/#live-demo

Vikrant
  • 444
  • 1
  • 5
  • 22