Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

onclick THIS element

<!DOCTYPE html>
//Note, this only works with a local script, it does not work if the HTML file
  //is linked to an external js file
  <html>
<body>

<h1>HTML DOM Events</h1>
<h2>The onclick Event</h2>
<h3 onclick="myFunction(this, 'red')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'green')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'blue')">Click me to change my text color.</h3>
<h3 onclick="myFunction(this, 'purple')">Click me to change my text color.</h3>
<script>
function myFunction(element, color) {
  element.style.color = color;
}
</script>

</body>
</html>
Source by javascript.divendo-webs.com #
 
PREVIOUS NEXT
Tagged: #onclick #THIS #element
ADD COMMENT
Topic
Name
9+6 =