Thursday, December 24, 2009

Re: [jQuery] Re: Attaching an event to a non-existing element?

From: "Sime Vidas" <sime.vidas@gmail.com>
> Second, I haven't heard the term "combo box" in relation to HTML....
> you mean a SELECT element, right?

Yes.

> To answer your question, I don't see why you couldn't attach the event
> handler after the AJAX response....
>
> 1. You get the AJAX response
> 2. You create the combo box
> 3. You append it to the DOM
> 4. You attach an event handler to it


Aha, probably I would need to learn a little more.

I have done it this way:

1. I created the AJAX request
2. I received the AJAX response in JSON format, and the content of the
response contains the full HTML code for creating the select element
starting with <select...> and ending with </select>.
3. I have set this response as the content of an empty div.

That select element appears well, but maybe it doesn't appear as a DOM
member, so that's why I can't attach an event handler to it.

Octavian

No comments: