Why won't .attr('checked','checked') set?

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-04-08T00:43:40Z Indexed on 2010/04/08 0:53 UTC
Read the original article Hit count: 464

Filed under:
|
|

I have the following snippet of code (I'm using jQuery 1.4.2):

$.post('/Ads/GetAdStatsRow/', { 'ad_id': id }, function(result) {
    $('#edit_ads_form tbody').prepend(result);
    $(result).find('td.select-ad input').attr('checked','checked').click();
});

Assume that the post works correctly and returns a correct pre-built <tr> with some <td>s. Here's the weirdness: the $(result).find() line finds the correct input (which is a checkbox, as it's the only input in the cell) and runs the chained click() function correctly, but it REFUSES to set the box as checked, which I need to happen.

Here's a crazy twist, too... when I get super specific and change the $(result).find() line to this (the id of the checkbox):

$('#ad_' + id).click();

It checks the box, but doesn't run the click() function! If I set it to

$('#ad_' + id).attr('checked','checked').click();

it runs the click function as though the box were checked, but the box remains unchecked, and if I do

$('#ad_' + id).click().attr('checked','checked');

it does nothing at all.

What in the world could be the matter with this? I'm running out of hair....

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about checkbox