tags:

views:

20

answers:

2

I am having <ul class= "list" id = "List">

I want to read the ul id

$("li:last-child input:button").live('click', function () { var val = $(this).closest('ul').val(); alert(val); });

How can I do that? In the above the alert is not displaying the id.

+1  A: 

val() returns an input's value. You want the ID attribute:

$("li:last-child input:button").live("click", function() {
  var id = $(this).closest("ul").attr("id");
  alert(id);
});

You can use attr() on a jQuery object or id on a DOM element object to get the ID.

cletus
A: 

You can do this:

  $("li:last-child input:button").live('click', function () { 
        var val =  $(this).closest('ul').attr('id'); 
        alert(val); 
  });
Manie