samedi 11 novembre 2017

Toggle checkbox checked attribute without jQuery

I have seen similar questions such as "How do I toggle an element's class in pure JavaScript?", but this question refers to attributes instead.

I have a checkbox like so:

<span class="newsletter-checkbox"><input type="checkbox" name="newsletter" id="newsletter" checked> Sign up to the newsletter as well - recieve new posts in your inbox</span>

How do I make it so that when anywhere in .newsletter-checkbox (including the text) is clicked, it toggles the checkbox checked attribute?




Aucun commentaire:

Enregistrer un commentaire