Answers for "javascript set onclick event with parameters"

3

javascript onclick parameters

<button onclick="myfunctionName('John')">Click</button>

<script type="text/javascript">
	function myfunctionName(String){
		alert(String);
	}
</script>
<!-- Will Show an Alert Box Saying "John" -->
Posted by: Guest on May-02-2021
0

javascript setattribute onclick function with parameters

var but = document.createElement('button');

var my_string = '123-45-lol , @%# ';

var but.setAttribute('onclick', 'my_function( " '+my_string+' " )');

// Or to use addEventListener() instead of setAttribute() ?
Posted by: Guest on April-06-2020

Code answers related to "javascript set onclick event with parameters"

Browse Popular Code Answers by Language