开发者

How to read the ul id?

开发者 https://www.devze.com 2023-01-10 14:27 出处:网络
I am having <ul class= \"list\" id = \"List\">开发者_开发知识库 I want 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

精彩评论

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