Skip to content
Advertisement

Button value output in console.log with JS

I’m fairly new to HTML and JS. I need the value of my HTML button to show in the console.log with JS. I dont want to use onclick=”…” though.

This is part of my HTML file:

JavaScript

This is my JS file:

JavaScript

Advertisement

Answer

1) You have to add event listener on the html element not on the value of that element.

JavaScript

2) After you click on the button you have to grab its value using price.value

JavaScript

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement