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:
- $(document).ready(function()
- {
- $('table#delTable td a.delete').click(function()
- {
-
- if (confirm("Eliminare il record?"))
- {
- var id = $("#unico").text();
- var data = 'id=' + id;
- var parent = $(this).parent().parent();
-
- $.ajax(
- {
- type: "POST",
- url: "Database",
- data: data,
- cache: false,
-
- success: function()
- {
- parent.fadeOut('slow', function() {$(this).remove();});
- }
- });
- }
- });
-
- $('table#delTable tr:odd').css('background',' #FFFFFF');
- });
- </script>
- </head>
- <body>
- <%
- final String selezione = ("SELECT * FROM anagrafica");
- ConnectionManager cm = new ConnectionManager();
- ResultSet rs = null;
- try {
- Statement st = (Statement) cm.getConnection().createStatement();
- rs = st.executeQuery(selezione);
- out.print("<table align='center' cellpadding='5' cellspacing='0' width='30%' id='delTable' bgcolor='#f6f6f6' style='border:1px solid #cccccc;'>");
- out.print("<tbody><tr>");
- out.print("<th align='left' style='border-bottom:1px solid #cccccc;'><strong>Nome</strong></th>");
- out.print("<th align='center' style='border-bottom:1px solid #cccccc;'><strong>Cognome</strong></th>");
- out.print("<th align='center' style='border-bottom:1px solid #cccccc;'><strong>Elimina</strong></th>");
- out.print("</tr>");
- while (rs.next()) {
- out.print("<tr id='1' style='background: rgb(255, 255, 255);'>");
- out.print("<td align='left'>"+rs.getString("Nome")+ "</td>");
- out.print("<td align='center'>"+rs.getString("Cognome")+ "</td>");
- out.print("<td style = 'display:none' id='unico' align='right'>"+rs.getInt("Id_unico")+ "</td>");
- out.print("<td align='center'><a href='#' class='delete' style='color:#FF0000;'><img alt='' align='absmiddle' border='0' src='delete.png'>"+"</a></td>");
- out.print("</tr>");
- }
- out.print("</tbody></table>");
- } catch (SQLException sqle) {
- sqle.printStackTrace();
- } finally{
- try {
- if(cm.getConnection()!=null) cm.getConnection().close();
- rs.close();
- } catch (SQLException sqle) {
- sqle.printStackTrace();
- }
- }
- %>
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.