How to open a dialog for opening an identifier

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 dynamically generated.

in my js I need to know what was clicked on.

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; }); 
+6
source share
3 answers

You can get the id of the one the liek button was clicked on:

 $('a[id*=dialog_link]').click(function(){ var id = $(this).attr('id'); console.log(id); }); 
+4
source

Use id^ instead of id* , id^ to indicate that id starting with the given text and id* matches if the given text is available in id , somewhere even at the end, for example 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 .

+9
source

This should return the reference number:

 $('a[id*=dialog_link]').click(function() { var id = $(this).attr('id').replace('dialog_link-',''); alert(id); }); 

Demo

I used the .replace() function to remove text

+2
source

Source: https://habr.com/ru/post/914566/


All Articles