+ 1

How does I add ID to the parameter

as the code shown below: https://code.sololearn.com/WyJoZ6wKcZ15/?ref=app

21st Jul 2018, 11:55 AM
Gladwyn Tay
Gladwyn Tay - avatar
11 Answers
+ 3
You could use dataset attribute, eg. <button class="btn" data-id="a">A button</button> <button class="btn" data-id="b">B button</button> in JavaScript, you could get the data attribute by const el = document.querySelectorAll('.btn'); alert(el[0].dataset.id); // output 'a' alert(el[1].dataset.id); // output 'b'
21st Jul 2018, 1:30 PM
CalviŐČ
CalviŐČ - avatar
+ 1
Could it be possible you use a variable which does not exist? The variable letters is not declared somewhere
21st Jul 2018, 12:13 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
thank you so much
21st Jul 2018, 12:42 PM
Gladwyn Tay
Gladwyn Tay - avatar
+ 1
thank you . i try to use target.id or event.target instead .
22nd Jul 2018, 1:29 PM
Gladwyn Tay
Gladwyn Tay - avatar
0
thanks in advance ,for helping me in my school project
21st Jul 2018, 11:57 AM
Gladwyn Tay
Gladwyn Tay - avatar
0
You wanna add an id to what?
21st Jul 2018, 11:58 AM
Jonas Schröter
Jonas Schröter - avatar
0
add the id of the alphabet button to the function name call check(letter)
21st Jul 2018, 11:59 AM
Gladwyn Tay
Gladwyn Tay - avatar
0
You mean the ID should be the parameter?
21st Jul 2018, 12:07 PM
Jonas Schröter
Jonas Schröter - avatar
0
yup
21st Jul 2018, 12:07 PM
Gladwyn Tay
Gladwyn Tay - avatar
0
No problem:)
21st Jul 2018, 12:47 PM
Jonas Schröter
Jonas Schröter - avatar
0
I'd suggest to use a real IDE such as Webstorm,which Highlights mistakes like this.
21st Jul 2018, 12:49 PM
Jonas Schröter
Jonas Schröter - avatar