lundi 30 novembre 2020

LABEL act on checkbox only if it's unchecked (or viceversa)

I have a checkbox but its status must be changed clicking not on itself (it's hidden in my code) but onto two links/buttons.

I thought about possibility to use the for attribute, defined for label tag.

For example:

<input type="checkbox" id="field">
<label for="field">Enable it</label>
<label for="field">Disable it</label>

The problem with this approach is that I'd need that each one label have effect only if checkbox status is in its opposite meaning. In other words, first label should have effect only if checkbox is unchecked, and the second one in the inverse situation.

Ok, sure with js is quite simple but, I was thinking about if maybe there could be other approaches, maybe with pure html using some (for me) unknown attribute or something else.




Aucun commentaire:

Enregistrer un commentaire