Call JavaScript function with parameter in HTML tag
Posted: 06 Apr 2015, 14:49
Hi,
I have the following code:
When I click on the image, the alert() is not executed, and I get this error in console:
How to add the "onclick" in the img tag so the test() function alerts the value "data"?
I have the following code:
Code: Select all
<img src="image.png" alt="Image" onclick="test(data)" />
<script>
function test(prm) {
alert(prm)
console.log(prm);
}
</script>
Code: Select all
ReferenceError: data is not defined