« STIC:Atelier graphisme, animation, interactivité et HTML5/Modification de contenu avec DOM » : différence entre les versions
Aller à la navigation
Aller à la recherche
(Page créée avec « <source lang="JavaScript"> <!DOCTYPE html> <html> <head> <title>Event handling</title> <script type = "text/javascript"> // Nom de la fonction exé... ») |
mAucun résumé des modifications |
||
Ligne 30 : | Ligne 30 : | ||
</html> | </html> | ||
</source> | </source> | ||
http://tecfa.unige.ch/guides/js/ex-intro/event-handler.html |
Dernière version du 24 mars 2015 à 20:16
<!DOCTYPE html>
<html>
<head>
<title>Event handling</title>
<script type = "text/javascript">
// Nom de la fonction exécutée lorsque la page a été chargée
window.onload = start;
function start() {
// on ajoute un écouteur d'événement pour les "clics" à l'élément box
var my_para_button = document.getElementById("box");
my_para_button = addEventListener("click", modifyText);
}
// fonction exécutée lors d'un clic
function modifyText() {
// get the box
var my_content = document.getElementById("content");
my_content.innerHTML = "That was so good";
}
</script>
</head>
<body>
<div id="box">
<p style="background-color:yellow" id="content">CLICK ME !</p>
</div>
</body>
</html>