I have the following HTML code (I'm using Bootstrap Twitter Modal):
<a href='#' data-toggle='modal' data-target='#myModal' id='g' data-id=1>Launch modal</a>
<div class="modal fade" id="myModal" 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">×</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><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
And the following JQuery code:
<script>
$('#g').click(function () {
alert($(this).data("id"));
});
</script>
I want that onclick the link, after the bootstrap modal will open, there will be alrt with the 'data-modal' value.
I tried the code above and it didn't work.
My question is how can I fix it? (I'm pretty new with JQuery...)