I have a table. In a cell of the table there is a link like this:
<a data-toggle="modal" data-id="xyz" href="#remoteModal" data-target="#remoteModal">SOME_TEXT</a>
.
When I click on this link should open a modal. Here's an example:
<div class="modal fade" id="remoteModal" tabindex="-1" role="dialog" aria-labelledby="remoteModal" aria-hidden="true">
Some HTML/PHP Code
</div>
The modal must perform some operations that depend on the value of "data-id" attribute. To be precise, in the javascript code I need to read this value:
<script type="text/javascript">
$(document).ready(function ( ) {
$('#remoteModal').on('show.bs.modal', function( event ) {
console.log( /* How do I read the value of data-id? */ );
});
});
I do not know how to read the value of this attribute in the javascript code of the modal.
Many thanks for your interest.
So here in data-id you wll get your "XYZ"
And I think you can access to
value
variable everywhere in this pageUse the
.relatedTarget
property mentioned in the Modal Event docs: