I've been coding chrome extension popup with js that calls with a parameter.
here is html file
<!DOCTYPE html>
<html>
<head></head>
<body>
<p id="demo">=a</p>
<button type="button" id="do-count1">Count1</button>
<button type="button" id="do-count2">Count2</button>
<script src="popup.js"></script>
</body>
</html>
since chrome extension js must be separated
popup.js
var a=0;
function count(k) {
a = a + k;
document.getElementById('demo').textContent = a;
}
document.getElementById('do-count1').onclick = count(2);
document.getElementById('do-count2').onclick = count(5);
when opening the popup window it gives 7, as those 2 functions executed automatically without clicking. further the buttons don't work.
a similar question was asked The Chrome extension popup is not working, click events are not handled
but my question one step advanced since i need to call js function with a parameter onclick.