开发者

Reading label Id

I'm having a table in which i'm creating a label dynamically.

'<td>' + '<label for="Name" id = ' + value + '>' + text + '</label></td>'

I want to retrieve the id of the label and I`m doing the following which is not working: How can I get the Id of the label?

function Rea开发者_开发知识库dNames() {
            $('#Table tr').each(function() {
                NameID.push($(this).find('label').val());
            });   } 


First of all, you'll have to you should correct the markup and include quotes for the id:

'<td><label for="Name" id="' + value + '">' + text + '</label></td>'

Next, $('label').attr('id') should get you the id.


Assuming you have multiple tr's and each has at least one (or exactly one) label

function ReadNames () {
    $('#Table tr td label').each(function () {
        NameID.push(this.id);
    });
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜