Get only a certain td value with JQuery

Get only a certain td value with JQuery

Hi all,

I would like to get a specific td value with JQuery, here it is my code:

  1. $(document).ready(function()
  2. {
  3.    $('table#delTable td a.delete').click(function()
  4.    {
  5.      
  6.        if (confirm("Eliminare il record?"))
  7.        {
  8.         var id = $("#unico").text();
  9.            var data = 'id=' + id;
  10.            var parent = $(this).parent().parent();
  11.  
  12.            $.ajax(
  13.            {
  14.                   type: "POST",
  15.                   url: "Database",
  16.                   data: data,
  17.                   cache: false,
  18.  
  19.                   success: function()
  20.                   {
  21.                    parent.fadeOut('slow', function() {$(this).remove();});
  22.                   }
  23.             });
  24.        }
  25.    });
  26.  
  27.    $('table#delTable tr:odd').css('background',' #FFFFFF');
  28. });
  29. </script>
  30. </head>
  31. <body>
  32. <%
  33. final String selezione = ("SELECT * FROM anagrafica");
  34. ConnectionManager cm = new ConnectionManager();
  35. ResultSet rs = null;
  36. try {
  37. Statement st = (Statement) cm.getConnection().createStatement();
  38. rs = st.executeQuery(selezione);
  39.     out.print("<table align='center' cellpadding='5' cellspacing='0' width='30%' id='delTable' bgcolor='#f6f6f6' style='border:1px solid #cccccc;'>");
  40.     out.print("<tbody><tr>");
  41.     out.print("<th align='left' style='border-bottom:1px solid #cccccc;'><strong>Nome</strong></th>");
  42.     out.print("<th align='center' style='border-bottom:1px solid #cccccc;'><strong>Cognome</strong></th>");
  43.     out.print("<th align='center' style='border-bottom:1px solid #cccccc;'><strong>Elimina</strong></th>");
  44.     out.print("</tr>");
  45. while (rs.next()) {
  46. out.print("<tr id='1' style='background: rgb(255, 255, 255);'>");
  47. out.print("<td align='left'>"+rs.getString("Nome")+ "</td>");
  48.         out.print("<td align='center'>"+rs.getString("Cognome")+ "</td>");
  49.         out.print("<td style = 'display:none' id='unico' align='right'>"+rs.getInt("Id_unico")+ "</td>");
  50.         out.print("<td align='center'><a href='#' class='delete' style='color:#FF0000;'><img alt='' align='absmiddle' border='0' src='delete.png'>"+"</a></td>");
  51.         out.print("</tr>");
  52. }
  53.     out.print("</tbody></table>");
  54. } catch (SQLException sqle) {
  55. sqle.printStackTrace();
  56. } finally{
  57. try {
  58.     if(cm.getConnection()!=null) cm.getConnection().close();
  59.     rs.close();
  60. } catch (SQLException sqle) {
  61. sqle.printStackTrace();
  62. }
  63.   }
  64. %>
The problem is that if my TD has got 3 elements with a unique ID for deleting a record in MySQL Database, and for example the elements in the td (#unico) are 1, 2 and 3 whenever element I click for deleting the first one will disappear, I was wondering if there is a function that when I click the delete icon in the td with the class (delete) it knows what row I'am clicking and get only that ID.

I also tried with $('td#delete').closest('td').text() but in that way I only get (123) all the ID in my TD.

Thank all for your replies.