Click me to change my text color.
A function is triggered when the p element is clicked. The function sets the color of the p element to red.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p id="demo" onclick="myFunction()">Click me to change my text color.</p>
<p>A function is triggered when the p element is 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>
Example of HTML onclick Event Attribute | Mouse Events Attribute |
Definition and Usage of Definition and Usage | Mouse Events Attribute |
Browser Support of HTML onclick Event Attribute | Mouse Events Attribute |
Syntax of HTML onclick Event Attribute | Mouse Events Attribute |
Attribute Values of HTML onclick Event Attribute | Mouse Events Attribute |
Technical Details of HTML onclick Event Attribute | Mouse Events Attribute |
How to Execute a JavaScript when a button is clicked | Mouse Events Attribute |
How to Click on a <p> element to change its text color to red | Mouse Events Attribute |
How to Click on a button to copy some text from an input field to another input field | Mouse Events Attribute |
List of Mouse Events Attribute | Mouse Events Attribute |
What is HTML onclick Event Attribute | Mouse Events Attribute |
What is HTML ondblclick Event Attribute | Mouse Events Attribute |
Type: | Html |
Category: | Web Tutorial |
Sub Category: | Mouse Events Attribute |
Uploaded by: | Admin |