+ 1
What is the code to make a button when clicked will show some text
3 Respuestas
+ 4
For that you need Javascript click event. Make a function who does whatever you want, and then give the click event to your button.
+ 3
<div id="sample">
<button type="button" onclick="myfun()">
<script type="text/javascript">
function myfun(){
document.getElementById("sample").innerHTML = "the text will you want to print after clicking the button";
}
</script>
This code will definitely work.
+ 1
Adhiksit Got ya!
A click event is raised whenever an element is clicked. To define your own handler function to handle the click event do this.
//get the button
var btn = document.getElementById('btn);
btn.addEventListener('click', function(){
//Do something on click
console.log('clicked');
});
Or simply do
btn.onClick = function(){
//Do something on click
console.log('clicked');
}
https://www.sololearn.com/learn/JavaScript/2758/