dimanche 23 décembre 2018

Open a link and active a checkbox

Im trying to create an element, which when clicked, both opens a hyperlink and actives a label connected to a checkbox. The element is a menu item. When that menu item is clicked, I want the anchor/link to be opened and the menu to be closed through CSS, hence the checkbox.

However, whenever I put the label inside the hyperlink, the checkbox gets checked, but the hyperlink does not get opened.

<a href="#anchor">
    <label for="checkbox">
        Menu Item
    </label>
</a>

When I put the hyperlink inside the label, the opposite happens: the link gets opened, but the checkbox does not get checked.

<label for="checkbox">
    <a href="#anchor">
        Menu Item
    </a>
</label>

Is it possible to active the label and open the hyperlink simultaneously without using JavaScript? If so, how?




Aucun commentaire:

Enregistrer un commentaire