var obj = function(){ this.div = $("<div><span class='hello'>Say Hello!</span></div>"); var self = this; $(document).on( "click", self.div.find(".hello"),function(){ alert("HELLO"); self.div.find(".hello").attr("class","was").text("Say was"); }); $(document).on( "click", self.div.find(".was"),function(){ alert("WAS"); self.div.find(".was").attr("class","hello").text("Say Hello!"); }); }; var oo = new obj(); $("body").append(oo.div);
Ich benutz normaler Weise direkt obj.click(function), daher hab ich keine erfahrung mit obj,on(), quasi kann das folgende mist sein.
Mit `this.div = $("<div><span class='hello'>Say Hello!</span></div>");`{:.language-javascript} erzeugst du zwar ein paar tolle Elemente, aber mit
~~~javascript
$(document).on( "click", self.div.find(".hello"),function(){
alert("HELLO");
self.div.find(".hello").attr("class","was").text("Say was");
});
Suchst du doch innerhalb des Dokuments oder?
$("body").append(oo.div);
Eingehangen werden sie erst nach dem Konstruktor-Aufruf.
MfG
bubble
--
If "god" had intended us to drink beer, he would have given us stomachs. - David Daye
If "god" had intended us to drink beer, he would have given us stomachs. - David Daye