I saw a recent discussion at work on how to approach code style for data attributes in #HTML
-
I saw a recent discussion at work on how to approach code style for data attributes in #HTML
When you want to use them as boolean, do you set the string "true" or leave it empty and check for the attribute existence?
-
I saw a recent discussion at work on how to approach code style for data attributes in #HTML
When you want to use them as boolean, do you set the string "true" or leave it empty and check for the attribute existence?
@dev by the specs, which drives the browser parser
Boolean properties are true when present, false when absent. They are also false when present with empty string. If they are true and should be XML valid they have the value of the name of the property as string.
`<input disabled=“disabled”> //false`
Data are always string, not a Bool, so when used needs to have a value, otherwise it will be “falsy” to JS (empty string)
-
I saw a recent discussion at work on how to approach code style for data attributes in #HTML
When you want to use them as boolean, do you set the string "true" or leave it empty and check for the attribute existence?
@dev My understanding is that for boolean attributes (e.g. checked on checkboxes) the HTML convention is attribute="attribute" if ones to fill in the value, otherwise just the empty string is fine.
https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
-
@dev My understanding is that for boolean attributes (e.g. checked on checkboxes) the HTML convention is attribute="attribute" if ones to fill in the value, otherwise just the empty string is fine.
https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
@oblomov When using `checked` or `hidden` I do like not to add any value.
```
<input type="checkbox" checked />
```Here's an interesting take with link to the HTML spec:
-
undefined oblomov@sociale.network shared this topic