Click on a <p> element to change its text color to red:
<!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>