thanks, live() do its job! i'm going to play with it a little more... thanks again.
On Nov 24, 9:04 pm, Marcos Aruj <marcos.a...@gmail.com> wrote: > BTW, if you go for the second approach, remember to add the class to the > node using span.addClass("toggle") or attr("class", "toggle"); > > > > > > On Tue, Nov 24, 2009 at 2:03 PM, Marcos Aruj <marcos.a...@gmail.com> wrote: > > It may be that you're attaching the click event listener before the node is > > actually created, so when it looks for nodes with class ".toggle", it > > doesn't exist yet. > > The document.ready event will be fired before you programatically create a > > node. Try something like this instead: > > > $("<span></span>).text("span text here").click(function() { > > console.log('span clicked'); > > }); > > > Or, depending on your needs, you can use the "live" method to attach events > > to current and future nodes: > > >http://docs.jquery.com/Events/live#typefn > > > something like: > > > $(document).ready(function(){ > > console.log('$ is loaded'); > > $('.toggle').live('click', function() { > > console.log('span clicked'); > > }); > > }); > > > Hope this helps > > > On Tue, Nov 24, 2009 at 1:24 PM, lorenx <lor...@gmail.com> wrote: > > >> hi and thanks for the answer... > > >> i'm on a "browser action" and i'm including jquery.js and others > >> scripts.js in my popup.html. > > >> i created a span with "toggle" class: > > >> var spanText = document.createTextNode('[ + ]'); > >> var span = document.createElement('span'); > >> span.className = 'toggle'; > >> span.style.cursor = 'pointer'; > >> span.appendChild(spanText); > > >> but this code only outputs "$ is loaded", no response when i click the > >> span: > > >> $(document).ready(function(){ > >> console.log('$ is loaded'); > >> $('.toggle').click(function(){ > >> console.log('span clicked'); > >> }); > >> }); > > >> On Nov 24, 8:13 pm, Marcos Aruj <marcos.a...@gmail.com> wrote: > >> > It is working fine for me, also doing some more complex things. In what > >> > context are you including the jQuery js file? > > >> > On Tue, Nov 24, 2009 at 1:03 PM, lorenx <lor...@gmail.com> wrote: > >> > > hi all, > >> > > i included the library and $(document).ready() works as expected. > > >> > > what i'm not able to do is, for example, a simple task like the > >> > > following: > >> > > assigned a class to a dom element, i'm not able to intercept the click > >> > > as i normally do with $('.className).click(). > > >> > > is there something i miss? > >> > > thanks very much. > > >> > > -- > > >> > > You received this message because you are subscribed to the Google > >> Groups > >> > > "Chromium-extensions" group. > >> > > To post to this group, send email to > >> chromium-extensi...@googlegroups.com. > >> > > To unsubscribe from this group, send email to > >> > > chromium-extensions+unsubscr...@googlegroups.com<chromium-extensions%2Bunsu > >> > > bscr...@googlegroups.com><chromium-extensions%2Bunsu > >> bscr...@googlegroups.com> > >> > > . > >> > > For more options, visit this group at > >> > >http://groups.google.com/group/chromium-extensions?hl=en. > > >> > -- > >> > Marcos Aruj Alvarez > >> > Ingeniero de Software > >> > ------------------------------- > >> > marcos.a...@gmail.com > >> > ----- > > >> -- > > >> You received this message because you are subscribed to the Google Groups > >> "Chromium-extensions" group. > >> To post to this group, send email to chromium-extensions@googlegroups.com > >> . > >> To unsubscribe from this group, send email to > >> chromium-extensions+unsubscr...@googlegroups.com<chromium-extensions%2Bunsu > >> bscr...@googlegroups.com> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/chromium-extensions?hl=en. > > > -- > > Marcos Aruj Alvarez > > Ingeniero de Software > > ------------------------------- > > marcos.a...@gmail.com > > ----- > > -- > Marcos Aruj Alvarez > Ingeniero de Software > ------------------------------- > marcos.a...@gmail.com > ----- -- You received this message because you are subscribed to the Google Groups "Chromium-extensions" group. To post to this group, send email to chromium-extensi...@googlegroups.com. To unsubscribe from this group, send email to chromium-extensions+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/chromium-extensions?hl=en.