I am messing with jQuery and JavaScript prototyping and made this tiny little thing to try and understand how jQ objects can be saved/accessed.
I made a single class that has a single property
var class1 = function(){
this.div = $('<div class = "test"/>');
}
I then made a few prototype methods to manipulate it, like changing its colour and html values.
Then I made two instances of the class and was able to alter each instance's individual DOM element.
var myDiv1 = new class1().build().colour('green').colour('red');
var myDiv2 = new class1().build().colour('red').doHTML();
I was really surprised to see that each class maintained a reference to a different DOM element, even though it was already appended to the <body>. I am wondering how this is actually working. Are there hidden DOM ids that the class or jQuery is keeping a reference to? How does it know which DOM element to manipulate?
Thank you.
Aucun commentaire:
Enregistrer un commentaire