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);
});
精彩评论