javascript - Store jQuery objects in an array/object -
i want create js array contains jquery objects this:
var oformfields = new object; oformfields.label = $(document.createelement('label')); oformfields.input = $(document.createelement('input'));
since crashes code, expect not possible. alternatives? simplified version, want include other properties i'm able re-use in code when building dynamic forms.
edit: seemed did work after all... wanted do, this:
var oformfields = new object; oformfields.name_field.label = $(document.createelement('label')).addclass('nam_field'); oformfields.name_field.input = $(document.createelement('input')).addclass('nam_field');
this break code. i'm pretty new jquery, coming php background i'm having troubles adjusting correct way work arrays / objects.
just use this:
var oformfields = { label: $('<label />'), input: $('<input />') };
you can create element directly using jquery. furthermore, mentioned in comments, should prefer object literal notation on new
syntax.
Comments
Post a Comment