So I'm new to JQuery and am trying to write a program which returns (console log for testing) the value of a button when it is clicked. For some reason my code does not register when the button is clicked, and additionally I don't think the right value is being parsed for the "car" parameter.
Here is my code (probably more than needed but not sure where I'm going wrong):
$(document).ready(function() {
$(":button").click(myFunction(this.value));
});
function myFunction(car) {
selection = car;
console.log(selection);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" name="newButton" value="Mercedes"> <br>
<input type="button" name="newButton" value="BMW"> <br>
<input type="button" name="newButton" value="Audi">
I expect the program to log the value of the button that is pressed, however it is currently logging nothing.
Thanks
input[type=button], notbutton.$("input[type='button']").on('click', myFunction(this.value));