[jQuery] Re: Event handling/propagation question

2009-02-20 Thread Liam Potter
$(document).ready(function () { $(div.clickable_element p).click( function () { $(this).parents(div.clickable_element).toggleClass(selected); }); }); spaceage wrote: A question re: event handling/propagation: I have a surrounding div and I want any click within the div (including

[jQuery] Re: Event handling/propagation question

2009-02-20 Thread spaceage
OK, so you have to independently assign a handler to all descendant elements in the div? Is there no better way via the parent div? On Feb 20, 8:07 am, Liam Potter radioactiv...@gmail.com wrote: $(document).ready(function () {     $(div.clickable_element p).click( function () {        

[jQuery] Re: Event handling/propagation question

2009-02-20 Thread Frederik Ring
I think it should be also working just this way: $('#mydiv').css('cursor','pointer').click(function(){ $(this).addClass('selected'); }); No need to select all the contents manually. On Feb 20, 5:16 pm, spaceage spaceageliv...@gmail.com wrote: OK, so you have to independently assign a handler

[jQuery] Re: Event handling/propagation question

2009-02-20 Thread spaceage
Actually, this works nicely (I think because of the use of this vs. event.target?): $('div.clickable_element').click(function() { $(this).toggleClass (selected); }); On Feb 20, 8:28 am, Frederik Ring frederik.r...@gmail.com wrote: I think it should be also working just this way:

[jQuery] Re: Event handling/propagation question

2009-02-20 Thread Liam Potter
I only used parents() and selected the P as that is what I understood spaceage wanted. spaceage wrote: Actually, this works nicely (I think because of the use of this vs. event.target?): $('div.clickable_element').click(function() { $(this).toggleClass (selected); }); On Feb 20, 8:28 am,