Javascript DOM HTML Paragraph handle click event

Introduction

Click on a <p> element to change its text color to red:

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo" onclick="myFunction()">Click me to change my text color.</p>

<script>
function myFunction() {//from ww w.  j ava2 s .  com
  document.getElementById("demo").style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related