html
<p id="tag_p"><p>
javascript
function a() {
return 1;
}
document.getElementById('tag_p').addEventListener('click', a);
I want to get return value,
Like let n = a();
, when click tag p.
html
<p id="tag_p"><p>
javascript
function a() {
return 1;
}
document.getElementById('tag_p').addEventListener('click', a);
I want to get return value,
Like let n = a();
, when click tag p.
You can process the result inside the EventHandler.
document.querySelector('#tag_p').addEventListener('click', function(evt){ console.log( "you clicked, I got: %d", a() );
This takes the result from the function "a" and outputs it as a number "%d" onto the browser console. More elaborately
document.getElementById('tag_p').addEventListener('click', function(evt){
let b = a();
b++;
b--;
console.log( "The value of A is (after +1 and -1): %d", b );
}
` tag>
– Jeremy Harris Mar 11 '20 at 14:24