In my application, I sometimes have to create elements dynamically, so I create them in javascript, but it make it hard for maintenance.
For example:

The above image is the information window when I click a point in the map, and in our application we have a similar requirement, we use javascript to create the whole DOM.
I do not think this is a good idea, any suggestion?
You’ve said you’re using Prototype. You could make use of its
Templateclass. You could even store templates on the server and demand-load them via ajax if you like (although I’d worry about the number of HTTP requests), in order to keep your code and your markup completely distinct.For instance, here’s a Prototype template for building a table row:
You have various options for where and how to store the template text:
display: none, extract them as HTML, and then reuse them.In all three of those cases, eventually you end up with a string containing the template text, e.g.:
(But again, you may not need to put it actually in the JavaScript.)
From the string, you make a template:
And then use it:
Note that (sadly) you do have to do the HTML escaping yourself (because Prototype’s templates aren’t specifically tied to HTML, you can use them for any situation where you have a templated string). Or you can make a fairly small change to the
Templateclass to do it for you (that’s what I did, when I was using Prototype; I actually made it possible to call functions on template items).