To pass a parameter in JavaScript function from HTML, add it in the
onclick
attribute like so: onclick="myFunction('parameter')"
.For example, you can pass Hello World!
string to myFunction
in onclick
listener of a button
like so:
<script>
function myFunction(text) {
alert(text);
}
</script>
<button onclick="myFunction('Hello World!')">I am a button!</button>