开发者

How to read the ul id?

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.


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.


You can do this:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜