开发者

traversing a particular tree from multiple element selector of multiple tree structure

can anyone help me with this code.

Everything is working fine except this piece of code is not working

    $(document).ready(      
        function()
        {
            $("a.delete").click(
                function ()
                {
                    var cnf = confirm("Are you sure you want to delete thi开发者_StackOverflow社区s ticket?");
                    if(cnf){
                        $.post($(this).attr('href'), 
                            { "ajx": true },
                            function(data){
                                    if(data.scs){
                                        /*this piece of code is not working*/
                                        $(this).closest('tr').remove();
                                        /*this piece of code is not working*/
                                        //alert("ticket was deleted");
                                    }
                                    else{
                                        alert("Error:: Ticket could not be deleted."+data.msg);
                                    }
                             }, "json");

                            //alert('the requested ticket was deleted.');
                    }
                    //alert();
                    return false;
                }                   
            );
        }
    );

i have a table and i want to delete the row containing the link which was clicked.

the table row is as

<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
 <td><?php echo ++$count; ?></td>
 <td><?php echo $row['name']; ?></td>
 <td><?php echo $row['eventname']; ?></td>
 <td>
  <div class="img">
  <img class='event' src="../upload/<?php echo $row['image']; ?>" alt="<?php echo $row['image']; ?>"/>
  </div>
 </td>
 <td><?php echo $row['status']; ?></td>
 <td><?php echo $row['date']; ?></td>
 <td><a href="addticket.php?action=edit&tid=<?php echo $row['id']; ?>">edit</a></td>
 <td><a class="delete" href="deleteticket.php?tid=<?php echo $row['id']; ?>" href="#">delete</a></td>     
</tr>    
<?php endwhile; ?>

UPDATE:: In my firebug console i get error message

g.nodeName is undefined
[Break On This Error] "first")return true;m=g;case "last":fo...Type===1||g.nodeName.toLowerCase()=== 


$("table").delegate("a.delete", "click", function(ev) {
  if(confirm("Are you sure you wish to delete this row?"))
    $(this).closest("tr").remove();
  ev.preventDefault();
});


The following should work - closest travels up the dom for the next "tr" and removes it

$('a.delete').click(function() {
  $(this).closest('tr').remove();
});

http://api.jquery.com/closest/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜