So I am doing a drum machine project on Freecodecamp, where I am failing this condition.
" When I click on a .drum-pad element, the audio clip contained in its child element should be triggered. " So how do I trigger child element(in this case the audio element,to play the audio) while clicking or pressing the parent element?
I wrote something like this
class Drumset extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this)
}
handleClick(e){
this.inputElement.click()
}
render() {
return (
<div>
<div id="drum-machine" class="containerx box-middle">
<div id="display">
<div class="container">
<div class="row">
<div class="col">
<button type="button" class="drum-pad" id="Heater-1" onClick={this.handleClick}>
Q
<audio
class="clip"
id="Q"
src="https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3"
type="audio/mpeg"
></audio>
Well I tried putting the onClick event on inner element, which doesn't work either.