i want to create DOM elements dynamically using jQuery.
so when i called something like this..
Code:
var element_wrapper=$.create('div','divtest','','','yes','orange','center','');
it should create div tag with all the attributes and style which are passing to the extended jQuery function as parameters.
I am giving the whole function below which i hope will give you some idea on what i am trying to do.
Code:
jQuery.create = function(elmtype,elmid,elmclass,elmchecked,elmstyle,elmbackgroundcolor,elmtextalign,elmtext) {
var args = arguments[0] || {}, elem = null;
var objname=elmlist[args]
if (args.constructor == String) {
if (arguments.length > 1) {
var typelist = objname[0];
for(var type in typelist)
{elem = document.createElement(type);
}
traverse(objname[1]);
function traverse(propertylist){
var nodelist={ "nodename":"css" ,"nodename":"attr"}
for(var node in nodelist){
for (var attr in propertylist)
if(jQuery.type(propertylist[attr])=="string")
{
jQuery(elem).nodelist[node](attr,eval("elm"+attr));
}
else{
// jQuery(elem).css("background-color","orange");
traverse(propertylist[attr]);
}
}
}
if ( !( jQuery.isEmptyObject(objname[2])))
{
for(var value in objname[2])
{elem = document.createTextNode(eval("elm"+value));
}
}
}
} return elem;
};
so i want to call the jQuery Function .attr and .css dynamically, as per the value that passed to the variable nodelist[node]. For that i used
jQuery(elem).nodelist[node](attr,eval("elm"+attr)); where nodelist have two values attr and css.
in my code everything works fine except the part of nodelist[node].
ie: 1. jQuery(elem).attr(attr,eval("elm"+attr));
and 2. jQuery(elem).css(attr,eval("elm"+attr)); is working fine.
so i assigned the values to an object and accessed it while creating the attributes.
var nodelist={ "nodename":"css" ,"nodename":"attr"}
So my question is how to refer a variable to call a function in jQuery?