Luca Ridolfo
Luca Ridolfo

Reputation: 17

modal appearing clicking on a cell of a table

I'm trying quite hard, due to my inexperience, to popup a modal created with bootstrap.js on an onclick event on different cells in a table. I put the onclick="openModal()" on the cell.

Then the script:

<script type="text/javascript">
function openModal(){

$('#modal').modal('show');}   </script>

And then the div:

  <div class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

Of course, the script is before the </body> tag and the div outside the table.

Is there anything wrong? I know that the onclick event is not that great of a solution, but I'm still in the newbie phase!

Thanks you for your help Luca

Upvotes: 0

Views: 502

Answers (1)

True Chase
True Chase

Reputation: 51

You forgot to add a id to your div modal.

<div id="modal" class="modal" tabindex="-1" role="dialog">

In Jquery you use '#' to select a id.

Upvotes: 1

Related Questions