Reputation: 33
I need to add my attributes dynamically to my input but it dosen't works.
this.nomRoot is the name of the component here 'input'.
this.lstAttr is an Array with the attributs like 'name' or 'checked'.
this.lstAttrValue is an Array with the attributs values like 'myCheckbox' or 'true'.
Here is my code :
Component("Input", {
add: function(element, type) {
html = $('<'+this.nomRoot+' type="'+ type +'" />').appendTo('#'+element);
for(key in this.lstAttr) {
alert(this.lstAttr[key]);
alert(this.lstAttrValue[key]);
$(html).attr("'"+this.lstAttr[key]+"', '"+this.lstAttrValue[key]+"'");
}
}
});
So my code run with firebug but dosen't add the attributs.
I tried something like that :
this.lstOptions was an array with the attributs and attributs values like "name, myCheckbox"
$("<"+this.nomRoot+" />").attr(this.lstOptions).appendTo(element);
Upvotes: 3
Views: 133
Reputation: 207557
You want to set the attribute and the value, just reference the two indexes. No need to build some sort of string.
$(html).attr(this.lstAttr[key], this.lstAttrValue[key]);
Upvotes: 3