使用jquery获取div的id

时间:2011-04-26 04:36:30

标签: jquery

<ItemTemplate>
<div class="list_row">
<div class="list_rowtext"  style="width: 16%; text-align: left; padding-left: 5px;"
<a href="#" id=<%# Eval("CourseId") %> class="delbutton">
<img  border="0" alt="Delete" />
</a>
<div>
<ItemTemplate>
I'm using below code to delete a row from listview.although row is deleted from db but not reflected in listvoew. actually i think  this code var tr_id =   $(this).closest(".list_row"); is not getting <div>.

$("a").click(function () {
        //Get the Id of the record to delete
        var record_id = $(this).attr("id");
        //Get the ListView Row reference
        var tr_id = $(this).closest(".list_row");
        alert(tr_id);
        // Ask user's confirmation before delete records
        if (confirm("Do you want to delete this record?")) {

            $.ajax({
                type: "POST",                 
                url: "DisplayCourses.aspx/DeleteCourses",
                data: "{'args': '" + record_id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function () {
                    tr_id.css("background-color", "lightgreen");
                    tr_id.fadeOut(500, function () {
                        tr_id.remove();
                    });
                }
            });
        }
        return false;
    });

1 个答案:

答案 0 :(得分:0)

我试图把它拼凑起来......

$('.delbutton').click(function() {

   // Here is the id that you want.
   var id = $(this).closest('.list_rowtext').attr('id');

   // Something like this is what you probably want to do.
   $(this).closest('.list_row').slideUp(500, function() { $(this).remove(); });

});