JavaScript onclick for dash button

Hi,
I m trying to implement a functionality where additional to callbacks, I have to use a JavaScript API (Web Speech).

My js code is similar to this

$(’#start-record-btn’).on(‘click’, function(e) {
alert(‘button clicked’);
if (noteContent.length) {
noteContent += ’ ';
}
recognition.start();
});

And App layout as this.

app.layout = html.Div([
html.Div([
html.Div([
html.Div([
html.Textarea(id=‘note-textarea’)
], className=‘input-single’)
]),
html.Button(id=‘start-record-btn’, children=‘Start’),
html.P(id=‘recording-instructions’, children=‘Start Recording’)
], className=‘container’)
])

How can I call specific javascript functions when a button is clicked? Any sample code for js onclick event with Dash is appreciated.

1 Like

Hi, you can try visdcc.Run_js, it allows you run javascript in callback .:slightly_smiling_face:

1 Like