Javascript DOM onclick Event via HTML Tag onclick attribute

Introduction

This example demonstrates how to assign an "onclick" event to a p element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p id="demo" onclick="myFunction()">Click me.</p>
<script>
function myFunction() {/*from   ww w  .  j  a  va  2s.co m*/
  document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>

</body>
</html>
Bubbles:
Cancelable:
Event type:
Supported HTML tags:












Yes
Yes
MouseEvent
All HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related