Checkbox with no checked attribute

I am dynamically adding checkboxes to each row of the table - 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
                return true;


and in the following way how i add item to table ...

        var checkbox = $("<input type='checkbox' 
                           id='checkbox_" + o.example_id + "' />");


        tmp = [checkbox[0].outerHTML,




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?


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 :


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 {




All Articles