First of all thanks for taking the time to trying to understand me ;)
Basically what I'm trying to do is the following.

Whenever I want to add special behaviour to elements on the form, I
add classes to the element, or add (I know this isn't compliant, but I
have yet to find a better way) custom attributes, for instance:

<input type="text" name="nameID" id="nameID" value="blablabla"

I attached an elementInitialisation() function to the onload of the
Once the document loaded, I have one function that does the
initialisation on the element.

I would loop over all elements that require initialisation in some
way, and call the initialiseElemen(el) method.
In that element, I do all checks (does the element need validation
added, does it require extra behaviour, ...) and I modify the element
adding the desired behaviour.  This works fantastically...

Unfortunately however, I also update the contents of my page using
ajax on several occasions which might also add elements to the
document that would require initialisation.  These elements would need
to be going through the initialiseElement(el) function as well...

I don't know how this can be done in the easiest way...  I want the
code to be as concise as possible.

Does this explain the situation to you?

I can provide you with a login to the site where I'm working on if you
need it so I can provide you with more detailed info...

Thanks a lot!

On Dec 7, 1:06 pm, david <david.brill...@gmail.com> wrote:
> Hi speedpacket,
> > Is there a way to observe the dom and automatically run newly created
> > elements through the initialise function?
> could you please explain a little more what is expected !
> Or perhaps if you have some available code ?
> --
> david
> On 4 déc, 13:19, "speedpac...@gmail.com" <speedpac...@gmail.com>
> wrote:
> > Hello there,
> > I have another question that I hope someone can give me some insight
> > too...
> > As I want all javascript code to be in a seperate file, I wrote a
> > function "initialiseElements" which literally takes an element and
> > initialises its behaviour based upon some attributes (classname for
> > instance).
> > Basically it takes the elemen, checks whether el.readAttribute
> > ("isInitialised") == false, and in that case processes the element
> > (adding tooltips for action images, adding onclick behaviour,
> > onmouseover behaviour, add validators to inputs and so on...)
> > When processed we set el.writeAttribute("isInitialised") = true so
> > that it will only process one element a single time...
> > I found this way of working to be going great, and I basically call
> > the initialiseElement method for each element upon loading the form,
> > making it a very generic process...
> > However (yes, there is a but!!!), I do have an issue of course when I
> > cal some ajax to update the content; in that case I need to initialise
> > the elements that have been added...
> > Is there a way to observe the dom and automatically run newly created
> > elements through the initialise function?
> > Would this be a good approach?
> > How do you guys deal with stuff like this?
> > thanks so much in advance again for your much appreciated feedback.


You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to