Jump to content

problems with DOM


Guest lewapryb

Recommended Posts

Guest lewapryb

Hi everybody!I have a question... I learn DOM from Java part and I would like to know can I create a node with a name that is chosen dynamically , I mean I want to have a function like that... public AddElement(to_which_node, "name of Element", type_of_element){ to_which_node.appendChild("name of Element");}is it possible????? - the dynamic names of Elements???

Link to comment
Share on other sites

I'm not sure with what language you are trying to accomplish this, but in javascript, it'd look something like this:

function addElement(parent, element_id, element_type){	var element = document.createElement(element_type);	element.id = element_id;	parent.appendChild(element);}

And you could use it like this:

var div = document.getElementById("mydiv");addElement(div, "test", "p");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...