I want my .on('click') function to add one to my number value every time the Html button is clicked. I can't find anywhere that has helped me and I have spent a long time looking and nothing helps. I have tried the basic numbers and math variables. but since I'm brand new to javascript I don't know where I'm going wrong
import 'bootstrap@4.6.0'
import $ from 'jquery'
const number = {
number:0
};
$('button')
.html('Click me') // Try edit it...
.on('click')
body {
height: 100vh;
}
<div class="d-flex h-100">
<button class="btn btn-warning m-auto">
Hi! Click me
</button>
</div>
<div class="d-flex h-100">
<button class="btn btn-warning m-auto">
Hi! Click me
</button>
<p id="result"></p>
</div>
Here is Plain Javascript
const addNum = document.querySelector('.btn');
let num = 0;
addNum.addEventListener('click', () =>{
let result = document.querySelector('#result');
result.innerHTML =num++;
});