-2

I have parent element like:

<span style="background: yellow; padding: 50px;" onClick="setCheckBox()"><span>
<span> </span> <input type="checkbox" name="f01" value="100"></span></span>

and js function:

function setCheckBox() {
 document.getElementsByTagName('input'[0].checked = 'true';
}

Want to change the checkbox input on parent click (yellow color)

Thanks in advance!

2
  • 1
    You are missing a ) after the tag name. Commented Jul 11, 2022 at 12:19
  • doesn't work after I add ")" Commented Jul 11, 2022 at 12:25

1 Answer 1

1

you would use .checked = true; like so

document.getElementsByTagName('input')[0].checked = true;
  <input type="checkbox" name="f01" value="100">

Sign up to request clarification or add additional context in comments.

5 Comments

Please check for dupes before posting an answer. Basic questions are always dupes, complex questions mostly are.
For some reason doesn't work for me
I put it inside the function and called the function on click
@ChrisG will do chief. use the id of your checkbox to find it
I edited function. @Mordor can you give me an example

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.