Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the id to open dialog box

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;
        });
like image 590
Asim Zaidi Avatar asked Apr 30 '12 18:04

Asim Zaidi


2 Answers

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.

like image 167
The Alpha Avatar answered Oct 12 '22 11:10

The Alpha


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);
});
like image 37
Evan Avatar answered Oct 12 '22 10:10

Evan