javascript - Checkbox without checked attribute -


i have been dynamically adding checkboxes each row within table - datatables.net . however, when check boxes, html not show checked attribute not allow me focus on rows checked checkboxes. if set checkbox checked attribute, yes, checked attribute visible. code here shows how i'm trying check checked attribute...

        var filtered_rows = example_data_table._('tr', {"filter":"applied"});          $.each(filtered_rows, function(i, el){             // if not checked, not include             if(!$(el[0]).is(':checked')){                 console.log(el[0]);                 return true;             }else{                 window.alert("hit");             }          ... 

and following how i'm appending element datatables.net table...

        var checkbox = $("<input type='checkbox'                             id='checkbox_" + o.example_id + "' />");          ...          tmp = [checkbox[0].outerhtml,         ...];         table_data.push(tmp);          ...          example_data_table.fncleartable(false);         example_data_table.fnadddata(table_data); 

in console, message n times:

<input type="checkbox" id="checkbox_3895">                  examples.php:189 


guess, i'm wondering why checked attribute never included when have checked checkbox?

the html markup attribute <input checked="" not designed show state of element @ runtime moment, define default state of when page renders first time.

mdn < input > docs states:

checked:

when value of type attribute radio or checkbox, presence of boolean attribute indicates control selected default; otherwise ignored.

the varying of checked state can target js dom property checked:

document.getelementbyid('myinput').checked; //(true / false) 

or css pseudo :checked:

#myinput:checked { } 

Comments

Popular posts from this blog