Horje

How to Double-click on a <p> element to change its text color to red

Double-click me to change my text color.

A function is triggered when the p element is double-clicked. The function sets the color of the p element to red.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<p id="demo" ondblclick="myFunction()">Double-click me to change my text color.</p>

<p>A function is triggered when the p element is double-clicked. The function sets the color of the p element to red.</p>

<script>
function myFunction() {
  document.getElementById("demo").style.color = "red";
}
</script>

</body>
</html>

Output should be:

How to Double-click on a <p> element to change its text color to red




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Mouse Events Attribute
Uploaded by:
Admin