Checkbox with no checked attribute

I am dynamically adding checkboxes to each row of the table - datatables.net. However, when I check the checkboxes, the html does not show any checked attribute, which then prevents me from focusing only on rows with checkboxes checked. If I have checked a checkbox with a checked attribute, then yes, the checked attribute will be visible. The code here shows how I am trying to validate a checked attribute ...

        var filtered_rows = example_data_table._('tr', {"filter":"applied"});

        $.each(filtered_rows, function(i, el){
            // If not checked, do not include
            if(!$(el[0]).is(':checked')){
                console.log(el[0]);
                return true;
            }else{
                window.alert("HIT");
            }
         ...

      

and in the following way how i add item to 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 the console, all I get is this message n times:

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

      


I guess I'm wondering why the checked attribute is never included even when I checked the checkbox?

+3


source to share


1 answer


The HTML markup attribute <input checked=""

is not really meant to show the state of an element at runtime, but to define its default state when the page is first rendered.

MDN <input> docs :

checked:

When the value of the type attribute is a radio or checkbox, the presence of this boolean attribute indicates that the control is selected by default; otherwise, it is ignored.

The only validation state change you can customize is the Js DOM property checked

:



document.getElementById('myInput').checked; //(true / false)

      

or Css pseudo :checked

:

#myInput:checked {
}

      

+3


source







All Articles