Is it correct to pass model reference directly to HTML element?
window.car = {
color: "blue",
maxSpeed: 200
}
var element = $("<div>");
car.$element = element;
element[0]._model = car;
$("") creates a new jQuery element. JQuery has wrapped elements saved inside in keys 0,1,2 ... so [0] return first wrapped HTMLelement. _model is only name of reference variable.
Use jQuery's data()
method for that. Adding new properties directly to DOM nodes may run into problems and is considered harmful.
maybe you could attach the object to a data-model
attribute instead of attaching it directly as a dom node property (it could be destructive), just using
$(element[0]).data('model', car);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With