Click on a <p> element to change its text color to red: - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {//  ww w  .j  ava2s.c  o m
    document.getElementById("demo").style.color = "red";
}
</script>

</body>
</html>

Related Tutorials