In this tutorial we will learn How To Change Text Onclick with JavaScript. For this we can use onclick attribute and innerHTML property.
Table of Contents
HTML Code
HTML Code is given below, we have one paragraph tag with onclick attribute.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Change Text Onclick with JavaScript</title>
</head>
<body>
<p onclick="changeText(this)">Click to change my Text.</p>
</body>
</html>
JavaScript Code
Take a look at the JavaScript code given below.
<script>
function changeText(event){
event.innerHTML='Thanks..';
}
</script>
On click, above function will be called and the statement inside will be executed which will change the text using innerHTML property.
Video Tutorial
Watch video tutorial on How To Change Text Onclick with JavaScript.