I have the following code snippet (I am 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(); });
Suppose mail works correctly and returns the correct pre-built <tr> with some <td> s. Here's the weird $(result).find() : the line $(result).find() finds the correct input (which is the checkbox, since it is the only input in the cell) and correctly executes the click() chain, but it REFUSES to set this field as checked, which I should happen.
Here's a crazy twist too ... when I get a superspecial value and change the line $(result).find() to this (checkbox identifier):
$('#ad_' + id).click();
It checks the checkbox, but does not execute the click() function! If I set it to
$('#ad_' + id).attr('checked','checked').click();
it starts the click function as if the checkbox were checked, but the window remains unchecked and if I do
$('#ad_' + id).click().attr('checked','checked');
he does not do anything.
What could be in the world? I'm running out of hair ...
Thanks!
EDIT
Here, as I set the click event in the call to $(function()) :
$('td.select-ad input').live('click',AdPreview.selectAd);
It works the same as for all other flags, and the added flag really works if you click manually.
EDIT 2
After some digging, I found that this:
$('#ad_' + id).click();
actually calls the click function in addition to checking the field. However, when the click function is called (I already checked that input was the correct checkbox, and it is)
var input = $(this); console.log(input.is(':checked'));
the log returns false, even if the field is really checked! GAH WTF