I want to create a html table dynamically using javascript.
here the element name and attributes will be passed to the function as shown below.
Code:
Code:
function createhtml(elementname,attr)
{
for(j=0;j<attrs.length;j++)
{
attr1=attr1.split("=")
atr=attr1[0];
//first method
window['o' + elementname].setAttribute(atr, attr1[1]);
//second method
var e=document.getElementById(elementnode)
e. window[atr]= attr1[1] }
}
here window['o' + elementname] is the element to which the attributes needs to be set.
atr is the name of attribute and attr1[1] is the value. To create an attribute dynamically which is in bold as shown in the code above.
here instead of giving
Code:
Code:
e. style.width= attr1[1]
i want to write
Code:
e.'the variable name'=attr1[1]
in both methods that i mentioned in my code null value error occurred.
how to achieve this?