![]() |
Definition and Usage
The Applies to
The
Browser Support
|
Example:
HTML
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<p>A function is triggered when the button is clicked. The function outputs some text in a p element with id="demo".</p>
<script>
function myFunction() { document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Example:
HTML
<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>
html onclick attribute |
How to Execute a JavaScript when a button is clicked | HTML Attribute |
How to Click on a <p> element to change its text color to red | HTML Attribute |
Type
: |
Develop |
Category
: |
Web Tutorial |
Sub Category
: |
HTML Attribute |
Uploaded by
: |
Admin |
Read Article https://horje.com/learn/1434/reference