JSX:
<input
type="checkbox"
defaultChecked={myfilter.includes("Banana")}
/>
<span
onClick={onClickHandler}
className="banana">Banana
</span>
Without React:
`<input
type="checkbox"
/>
<span
className="banana">Banana
</span>`
The goal is to select and style the span element when the input element status is checked. The reason why I need to do this way is that the checkbox element is hidden by default. I tried this, but did not worked:
input[type="checkbox"]:checked + :after{
background: yellow;
}
chamhe :after
to span
\
input[type="checkbox"]:checked + span{
background: yellow;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.