0

I am trying to to make a function that calls a button click. I know how to do this using document.getElementById('takePic').click() but I am not sure how to do this in React.

I am using an input element in order to access a devices camera, but unfortunately the input button that generates cannot be easily formatted.

<input className={classes.takePic} type="file" accept="image/*"></input>

So what I want to do is set this input element's display to none and then instantiate the button click through the click of another button.

<Button className={classes.addImage} onClick="">

I am using material-ui if that makes a difference.

1 Answer 1

2

you can do this way :

<input id="takePic" className={classes.takePic} type="file" accept="image/*" />

<Button className={classes.addImage} onClick={this.handleClick}>


 handleClick=()=>{
   document.getElementById('takePic').click();
}

read more here : https://www.w3schools.com/jsref/met_html_click.asp

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

2 Comments

yes , it is HTML dom click() method , in javascript
Have to wait 15 minutes from the time of the post. But I will

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.