Bonsoirs à tous,

Je commence de suite par le vif du sujet, le script...:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
<html>
<head>
<script>
var maClass =  function()
     {
     this.element = null ;
     this.elementWidth = null ;
     }
 
maClass.prototype.config()
     {
     this.elementWidth = document.getElementById(this.element).offsetWidth ;
     document.getElementById(this.element).onclick = this.trying ;
     }
 
maClass.prototype.trying()
     {
      alert(this.elementWidth) ;
     }
</script>
</head>
<body>
<span class="monSpan" id="monSpan">Push</span>
<script>
 
var monObjet = new maClass() ;
monObjet.element = "monSpan" ;
monObjet.config() ;
 
</script>
</body>
</html>
Ma question est la suivante :

Avec un script tel que celui-ci, comment garder la valeur des attributs, d'une méthode à l'autre, lors d'évènement de type "onclick", "onmouseover", "onkeyup", etc... ?

Ce script renvoie au onclick un alert("undefined").

Merci à tous pour vos réponses.