I have a table containing records taken from a database. I have a button for each record which makes a dialogue box appear when clicked.
<img src="<?php echo config_item('base_url'); ?>library/images/ui/buttons/delete.png" class="bookmark-delete" data-bookmark="<?php echo $array_bookmarks_for_manage['bookmark_id']; ?>" height="14" width="14" />
Each button is a graphic and has a data attribute attached to it containing the ID of each record.
I'm trying to get the value of a data attribute to appear in the dialogue box.
My Code:-
$(document).ready(function() {
$("#dialogue").hide();
$("a.action").attr("href", base_url + 'bookmarks/delete/' + **$('.bookmark-delete').data('bookmark')**);
$('.bookmark-delete').click(function(event) {
$("#dialogue").css( { position:"absolute", top: event.pageY+15, left: event.pageX-315 });
$("#dialogue").show();
});
$('#close').click(function() {
$("#dialogue").hide();
});
});
And this:
$(document).ready(function() {
$("#dialogue").hide();
$("a.action").attr("href", base_url + 'bookmarks/delete/' + **$(this).data('bookmark')**);
$('.bookmark-delete').click(function(event) {
$("#dialogue").css( { position:"absolute", top: event.pageY+15, left: event.pageX-315 });
$("#dialogue").show();
});
$('#close').click(function() {
$("#dialogue").hide();
});
});
And also this:
$(document).ready(function() {
$("#dialogue").hide();
$("a.action").attr("href", base_url + 'bookmarks/delete/' + **$(this).attr('data-bookmark')**);
$('.bookmark-delete').click(function(event) {
$("#dialogue").css( { position:"absolute", top: event.pageY+15, left: event.pageX-315 });
$("#dialogue").show();
});
$('#close').click(function() {
$("#dialogue").hide();
});
});
All with no joy; every attempt either results in "undefined" or the last record ID in the table.
Everything else works except the retrieval of the value on third line of each example, which I've emboldened for emphasis.
The dialogue box is positioned outside of and after the table:
<div id="dialogue">
<h3>Delete Bookmark</h3>
<p>Do you want to delete this Bookmark?</p>
<div class="divider"></div>
<ul class="buttons">
<li><div id="button-link"><a class="button-link action" href="#">Delete</a></div></li>
<li><div id="button-link"><a class="button-link" href="#close" id="close">Cancel</a></div></li>
</ul>
<div class="cleaner"></div>
</div>
Also, here's a JS Fiddle of what I have. Please be aware, that for some reason, the code doesn't work at all on JS Fiddle, even though everything but the ID works here locally.
Any ideas?