[jQuery] Re: live event with instant execution
Hi, What you say is exactly what the alternative would be. Just you have better insight of what is needed... I have a class tip_class. Each element that has this class needs to have a tooltip initiated. What I do when the page is loaded, is indeed loop through all elements that have this class, and execute the flexinInitialiseElement method which does indeed create the tooltip when the element has this class (or does other initialisations, based on the classes added to the element...) I'm using jqGrid (http://www.trirand.com/jqgridwiki/doku.php), and one of the columns in the grid basically is a list of icons with a link for each action that can be performed on the object associated with the record in the grid. This works good, and the code is something liks: a href=linkimg src=url class=tipcaption/a I need javascript to be executed on these elements, without the need for me to explicitely write it or call the flexinInitialiseElement method upon refreshing the grid's content. Basically, the classes should be the driver for executing initialisation code, which I hoped I could achieve with the live option... Does this make myself more clear? :) David. On 25 dec, 20:07, Šime Vidas sime.vi...@gmail.com wrote: The load event wont help you... it has to do with stuff having finished loading, but you are creating new elements based on an AJAX response, so the new elements are not being loaded at all. Well, you can allways initialize the elements after you create them I can't see the problem For example. 1. you get the AJAX response 2. you create new elements 3. you initialize them
[jQuery] Re: live event with instant execution
Basically execute additional javascript code based on a classname adding functionality to these elements... I tried the following, but it doesn't seem to be working... jQuery('*').load(function () { // run code console.log(DEBUG: Initialising element + jQuery(this)); flexinInitialiseElement(jQuery(this), false); }); This piece of code is added to the top of the page, so I would have expected each DOM element to be passed to the flexinInitialiseElement method, but it doesn't... Thanks for the much appreciated feedback on this great Christmas day :) David. On 24 dec, 14:14, Šime Vidas sime.vi...@gmail.com wrote: What does initiating elements mean?
[jQuery] Re: live event with instant execution
The load event wont help you... it has to do with stuff having finished loading, but you are creating new elements based on an AJAX response, so the new elements are not being loaded at all. Well, you can allways initialize the elements after you create them I can't see the problem For example. 1. you get the AJAX response 2. you create new elements 3. you initialize them
[jQuery] Re: live event with instant execution
Hi! I'm not really sure of what you're trying to do, but the main problem is that you're not passing all selectors to your flexinInitialiseElement method. Maybe somethingl like this will help you. It's iterationg through all dom nodes and passing them to flexinInitialiseElement. $(*).each(function(){ var $this = $(this); flexinInitialiseElement( $this, false) }) The entire code is really bad if performance is an issue, so maybe a small vanilla js would do fine here, like this: var nodes = $(*); for (i=0; i nodes.length; i++) { flexinInitialiseElement( nodes[i] , false) } Hope this will help you somewhere :) / Johan On 25 Dec, 12:57, speedpac...@gmail.com speedpac...@gmail.com wrote: Basically execute additional javascript code based on a classname adding functionality to these elements... I tried the following, but it doesn't seem to be working... jQuery('*').load(function () { // run code console.log(DEBUG: Initialising element + jQuery(this)); flexinInitialiseElement(jQuery(this), false); }); This piece of code is added to the top of the page, so I would have expected each DOM element to be passed to the flexinInitialiseElement method, but it doesn't... Thanks for the much appreciated feedback on this great Christmas day :) David. On 24 dec, 14:14, Šime Vidas sime.vi...@gmail.com wrote: What does initiating elements mean?
[jQuery] Re: live event with instant execution
Hmm - not sure if correct, but would the load event be the one I should be looking at? Sorry for answering my own question, but if someone could confirm, i would feel a lot better ;) David. On 24 dec, 11:28, speedpac...@gmail.com speedpac...@gmail.com wrote: Hi, I do have elements which are being initiated when dom is ready based on css selectors. this works like a charm, and when the dom is ready, I have a function which initialises all elements in the dom based on the selectors. The page however also comes with quite some ajax which inserts new elements, and I want these elements to be initialised as well. I have read about the live event, but it appears to be requiring another event where the behaviour will finally be attached to. Is there a way to pass new elements to a function which is responsible for the initialisation thereof without the need of relying on an even other than the fact that it is created? (or simply put: why isn't there an event onCreate :) ) I hope someone is able to help me with this... Thanks! David.
[jQuery] Re: live event with instant execution
What does initiating elements mean?