Answers for "setattribute onclick"

3

set onclick javascript

<button id="myBtn">Try it</button>
<p id="demo"></p>

<script>
document.getElementById("myBtn").onclick=function(){displayDate()};

function displayDate()
{
    document.getElementById("demo").innerHTML=Date();
}
</script>
Posted by: Guest on December-18-2020
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"

Browse Popular Code Answers by Language