Manish Prajapati
Manish Prajapati

Reputation: 1641

How to get check box value of a attribute

i want to get value of attribute value of checkboxes. my code is giving me undefined

$('#mytable').find('tr').each(function () {
            var row = $(this);

            if ( row.find('input[type="checkbox"]').is(':checked') ) {
                alert( $(this).attr("b_partner_id") );
            }
        });

Upvotes: 4

Views: 29

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

this is referring to the tr element in the if block, since your b_partner_id attribute is not present in the tr element you are getting undefined.

Instead you need to get the attribute value using the checkbox reference

$('#mytable').find('tr').each(function () {
    var row = $(this),
        $check = row.find('input[type="checkbox"]');

    if ($check.is(':checked')) {
        alert($check.attr("b_partner_id"));
    }
});

Upvotes: 5

Related Questions