0
 <input type="checkbox" name="smoker">

How do I get JavaScript to recognize if the box is checked or unchecked without altering the the above HTML code.

2

1 Answer 1

0

Use querySelector and get the element by name

let val = document.querySelector('[name="smoker"]').checked;
console.log(val);
Sign up to request clarification or add additional context in comments.

1 Comment

@mason-white was this to any help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.