|
on... - Wenn-Elemente | |||
Tag | Beschreibung | Wert | Beispiel |
onclick |
Script to be run when the element is being clicked |
All visible elements. |
<button onclick="myFunction()">Click me</button> <p id="demo" onclick="myFunction()">Click me to change my text color.</p> <script>function myFunction() { document.getElementById("demo").style.color = "red";}</script> <p id="text" onclick="func()"> Click to change color</p> <script>function func() {document.getElementById("text").style.color="red"; document.getElementById("text").style.font="calibri";} </script> |
onload |
Script to be run when the element is finished loading |
Das onload-Attribut ist Teil der Ereignisattribute und kann für die folgenden Elemente verwendet werden: <body> <iframe> <img> <input> <link> <script> <style> |
<script>function myFunction() { alert("Page is loaded");}</script> </head> <body onload="myFunction()"> <h1>Hello World!</h1></body> |
onmouseover |
Script to be run when a mouse pointer moves over an element |
All visible elements. |
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="smiley.gif" alt="Smiley" width="32" height="32"> |
open |
Specifies that the details should be visible (open) to the user |
<details> |
<details open> <summary>Epcot Center</summary> <p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p> </details> <p>This example demonstrates a details element that is open by default.</p> |
onchange | <select onchange="myFunction()"> | ||
oncanplaythrough |
<audio id="myAudio" controls oncanplaythrough="myFunction()"> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> | ||
onbeforeunload | Führt ein JavaScript aus, wenn die Seite entladen werden soll | <body onbeforeunload="return myFunction()"> | |
ondblclick | Ausführen eines JavaScripts, wenn auf eine Schaltfläche doppelgeklickt wird | <button ondblclick="myFunction()">Double-click me</button> | |