Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome DevTools not showing "checked" or "checked="true" attribute in html tag

In the Chrome DevTools, how can you know if a checkbox or radio button is checked. When you click on any of the above, the attribute checked is not showing at all. It's annoying because I have to guess what's happening and it kind make development process slower. Is there some settings I need to apply?

like image 290
Shaoz Avatar asked Dec 11 '22 05:12

Shaoz


1 Answers

A checkbox has two attributes that talk about it being checked: One is an HTML/DOM attribute, and one is a property of the scripting object. (dom-input-checked and attr-input-checked in the spec, respectively).

The spec sometimes uses the word reflect to indicate that these two kinds of attributes are kept in sync, but it does not in this case: The DOM attribute is the default checked state, and the IDL attribute is the current checked state. This allows to "Reset" a form, for instance.

Example of the attributes being different:

console.log([a.checked, a.getAttribute("checked")]);
a.checked = false;
console.log([a.checked, a.getAttribute("checked")]);

console.log([b.checked, b.getAttribute("checked")]);
b.checked = true;
console.log([b.checked, b.getAttribute("checked")]);
<input type=checkbox id=a checked>
<input type=checkbox id=b>

Anyway, you can use the "Properties" tab in Chrome's devtools to see the other attribute.

enter image description here

(In Firefox this is under Right click > Show DOM Properties, but you have to select the correct iframe first.)

like image 123
Josh Lee Avatar answered Jun 06 '23 08:06

Josh Lee