JSFiddle - React, Tailwind, and code Playground
by Dedi Wibisono
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<button type="button" class="popup btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-content="2">
Launch demo modal 1
</button>
<button type="button" class="popup btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-content="1">
Launch demo modal 2
</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
CSS
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
JavaScript
var test = [{
'name':'john',
'id':1
},{
'name':'doe',
'id':2
}]
$(document).on('click','.popup',(e)=>{ var id_ = parseInt(e.target.getAttribute("data-content")); const res = test.filter((v) => v.id == id_); $("#exampleModal .modal-body").html(""); $("#exampleModal .modal-body").html(` <p>${res[0].name}</p> `) })