I have the following code
<td><a href="#" id="dialog_link-19" class="ui-state-default ui-corner-all">Click here</a></td>
<td><a href="#" id="dialog_link-25" class="ui-state-default ui-corner-all">Click here</a></td>
<td><a href="#" id="dialog_link-33" class="ui-state-default ui-corner-all">Click here</a></td>
<td><a href="#" id="dialog_link-556" class="ui-state-default ui-corner-all">Click here</a></td>
#dialog_link
is generated dynamically.
in my js I need to know which was clicked.
this is my js
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#dialog_link').click(function(){
$('#dialog').dialog('open');
$.ajax({
url: "teams/pp",
type: "POST",
data:
success: function( data ){
console.log(data);
}
});
return false;
});
Use id^
instead of id*
, id^
used to indicate that the id
beginning with the given text and id*
matches if the given text is available in the id
, anywhere even at last like id1-dialog_link
:
$("td a[id^='dialog_link']").click(function(){
var id = $(this).prop('id');
console.log(id);
});
Here a[id^='dialog_link']
will match dialog_link-19
but not id1-dialog_link
.
You can get the id of the one which was clicked liek this:
$('a[id*=dialog_link]').click(function(){
var id = $(this).attr('id');
console.log(id);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With