+ 1

pass element's data to function's parameter when using onclick event listener?

HTML: <input class="c" id="1" type="button" onclick="func()"/> JavaScript: func(parameter) { scripts } I basically want to pass 1 (id name) to the parameter when the button is clicked. or if the button is the third element in the page which has class name of "c", I want to pass 3 to the function when it's clicked. Is there any way?

3rd Jan 2019, 10:41 AM
Parsa Gholipout
Parsa Gholipout - avatar
1 Respuesta
+ 2
HTML <input class="c" id="1" type="button" onclick="func(this.id)" value="Test 1"/> JS function func(id) { alert(id); } Hth, cmiiw
3rd Jan 2019, 11:09 AM
Ipang