When creating a web page who's content will be created and destroyed dynamically by the user, what is the best way to structure and initialize both the javascript functionality and the DOM Elements?
Example -- Lets say you have a todo-list who's items can be re-ordered, created, and destroyed by the user:
- Each Item will have a visual representation (ie. Dom elements) which will need to be created dynamically when the user adds an item
- Each item will also have a javascript representation (ie. javascript objects with custom methods and attributes) which will be instantiated when the user adds an item
What is the bet way to deal with creating the initial DOM elements and their javascript representation? I can see a couple possibilities:
- have the server spit out the structured HTML and have the JS glean the initial state by walking the DOM.
- have the server spit out the structured HTML and some JS code to create the set of objects and associate them with their DOM representation.
- have the server spit out JS objects and dynamically create the DOM elements once the page is loaded.