0

Hi,

I know it's possible to add actions for elements that are not in DOM yet, like
$(element).live('event',function() {
//code here
});

Is there any way to execute the code without the event, or give it an event like 'exists' ? Like, when object is added, the function executes automatically, so i don't have to click or mouseover the element or something like that.

Thanks

Edited by Buppy: n/a

4
Contributors
7
Replies
14
Views
6 Years
Discussion Span
Last Post by kela_wala
0

What do you mean by, "when object is added"? What object and added to what? Live and bind are both used for event binding.

Can you try to explain better what you are trying to do and give a good example please.

0

For example, i create a new element with document.createElement('div');
I need to execute an action when the element is created. As far as i have found, .live and .bind allows only events on action (like i click the new element or something), but i need an event when the element is first introduced.

P.S. The element creation code is out of my reach. An action after document.createElement('div'); won't be an option.

Edited by Buppy: n/a

0

The only way I can think of (and this is ugly and this is assuming you know what type of element. ie div, input, a, hr, table...) is to have a setInterval that is constantly checking the number of those elements on the page and when there is one more element than the last, execute some code.

Of course this is all on the assumption also that you don't have access to the code that adds the element to the page.

0

Well, the code that creates element is an external script (mailchimp), which posts my form to it's page, generates stuff there and inserts response into my page.

0

Ask the developers. Perhaps there is a way to register a callback, so you can get notified when something is inserted.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.