JSFiddle - React, Tailwind, and code Playground
by techiedelight
HTML
<!doctype html>
<html>
<body>
<p>Choose your gender:</p>
<div>
<input type="checkbox" id="male" name="gender" value="male" checked>
<label for="male">male</label>
</div>
<div>
<input type="checkbox" id="female" name="gender" value="female">
<label for="female">female</label>
</div>
<div>
<button id="submit">Get Value</button>
</div>
<br>
</body>
</html>
CSS
p,
label {
font: 15px 'Exo 2', sans-serif;
}
input {
margin: 6px;
}
button {
margin-top: 10px;
padding: 2 2;
font: 15px 'Exo 2', sans-serif;
}
JavaScript
document.getElementById('submit').onclick = function() {
if (document.getElementById('male').checked) {
alert(document.getElementById('male').value);
} else if (document.getElementById('female').checked) {
alert(document.getElementById('female').value);
}
}