[jQuery] Re: Selector issue
Well, after a few tests, this works fine : $(#cat_list div).live(click, function() { alert($(this).attr(id)); }); thanx
[jQuery] Re: Selector issue
I wouldn't suggest going the .live route if you plan on having a lot of children of cat_list using event delegation, there is one single event wired up that handles 1 child or 1200 children using .live, you would have N number of events sitting there wired up where N is the number of children. but whatever works i suppose On Dec 4, 3:35 am, Civette la.cive...@gmail.com wrote: Well, after a few tests, this works fine : $(#cat_list div).live(click, function() { alert($(this).attr(id)); }); thanx
Re: [jQuery] Re: Selector issue
On Dec 4, 2009, at 11:09 AM, MorningZ wrote: I wouldn't suggest going the .live route if you plan on having a lot of children of cat_list using event delegation, there is one single event wired up that handles 1 child or 1200 children using .live, you would have N number of events sitting there wired up where N is the number of children. but whatever works i suppose Nah. Using .live() wires up one event handler to document. --Karl Karl Swedberg www.englishrules.com www.learningjquery.com
[jQuery] Re: Selector issue
Well I dont think I'll have more than about 15 childs here. Thx for help On 4 déc, 17:09, MorningZ morni...@gmail.com wrote: I wouldn't suggest going the .live route if you plan on having a lot of children of cat_list using event delegation, there is one single event wired up that handles 1 child or 1200 children using .live, you would have N number of events sitting there wired up where N is the number of children. but whatever works i suppose On Dec 4, 3:35 am, Civette la.cive...@gmail.com wrote: Well, after a few tests, this works fine : $(#cat_list div).live(click, function() { alert($(this).attr(id)); }); thanx
[jQuery] Re: Selector issue
Nah. Using .live() wires up one event handler to document. --Karl Doh, shame on me for my lack of facts on that .live()... i'll read up on it some, as i usually, well always, take the delegation route..
Re: [jQuery] Re: Selector issue
The .live() method uses event delegation under the hood. doing this: $('a').live('click', function() { // do something }); is like doing this: $(document).bind('click', function(event) { if ($(event.target).closest('a').length) { // do something } }); except that with .live() the selector engine does have to initially traverse the DOM to find all of the a elements just by virtue of 'a' being in the jQuery function. not sure, but that might be changing in 1.4. Also, I haven't had a chance to look yet, but 1.4 also might let you pass in a context for .live() so you don't have to bind to document each time. --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Dec 4, 2009, at 3:39 PM, MorningZ wrote: Nah. Using .live() wires up one event handler to document. --Karl Doh, shame on me for my lack of facts on that .live()... i'll read up on it some, as i usually, well always, take the delegation route..
[jQuery] Re: Selector issue
I'm relative new to jQuery, but I usually use function(e) instead of function() within a click handlers, because when you do it on a selector that do not return a single element (#cat_list div returns several dom element) you cannot access the data you need (e.target is the element you clicked). #cat_list return a single dom element and it's not a problem I don't know if this is the issue On 3 Dic, 16:03, Civette la.cive...@gmail.com wrote: Well i'm in trouble. Following code does not trigger : Code: Select all $(#cat_list div).click(function() { alert(Bye bye!);; }); neither Code: Select all $(#cat_list ~ div).click(function() { alert(Bye bye!);; }); or Code: Select all $(#cat_list *).click(function() { alert(Bye bye!);; }); Altough this works : Code: Select all $(#cat_list).click(function() { alert(Bye bye!);; }); HTML code looks like : div id=cat_list div id=39a/div div id=40b/div ... /div Any idea ? thanks
[jQuery] Re: Selector issue
the first one works perfectly fine in stripped down form http://jsbin.com/epoju/edit must be something else with other code you are doing On Dec 3, 10:03 am, Civette la.cive...@gmail.com wrote: Well i'm in trouble. Following code does not trigger : Code: Select all $(#cat_list div).click(function() { alert(Bye bye!);; }); neither Code: Select all $(#cat_list ~ div).click(function() { alert(Bye bye!);; }); or Code: Select all $(#cat_list *).click(function() { alert(Bye bye!);; }); Altough this works : Code: Select all $(#cat_list).click(function() { alert(Bye bye!);; }); HTML code looks like : div id=cat_list div id=39a/div div id=40b/div ... /div Any idea ? thanks
[jQuery] Re: Selector issue
Well, actually my div 39, 40, are returned in the cat_list div from a previous ajax query. Numbers are in fact the autoincrement id's in a mysql table. Point is, on clicking each, to edit it. That specific javascript part is returned by that ajax query.
[jQuery] Re: Selector issue
if those div's are dynamically added, which it sounds like is the case, then the new div's do not get wired automatically... - this is easily the most common trip-up seen on this mailing list Event Delegation would be your friend here http://jsbin.com/ivivo/edit that way the container event cat_list has the event and you can add/ remove children from it as you please On Dec 3, 4:10 pm, Civette la.cive...@gmail.com wrote: Well, actually my div 39, 40, are returned in the cat_list div from a previous ajax query. Numbers are in fact the autoincrement id's in a mysql table. Point is, on clicking each, to edit it. That specific javascript part is returned by that ajax query.
[jQuery] Re: Selector issue
I'll test it tomorrow. Thx for answer
[jQuery] Re: Selector issue
Is your issue description linked to this : http://forum.jquery.com/viewtopic.php?f=2t=1000sid=7932d86732f0126e2c4ad3f5e92baa4d Same thing ? On Dec 3, 10:52 pm, MorningZ morni...@gmail.com wrote: if those div's are dynamically added, which it sounds like is the case, then the new div's do not get wired automatically... - this is easily the most common trip-up seen on this mailing list Event Delegation would be your friend here http://jsbin.com/ivivo/edit that way the container event cat_list has the event and you can add/ remove children from it as you please On Dec 3, 4:10 pm, Civette la.cive...@gmail.com wrote: Well, actually my div 39, 40, are returned in the cat_list div from a previous ajax query. Numbers are in fact the autoincrement id's in a mysql table. Point is, on clicking each, to edit it. That specific javascript part is returned by that ajax query.