That code is fine. It would have been much simpler if you had said from the beginning you were going to attach a different click handler for the LI elements! The 'return false' in it prevents the click event from bubbling up to the DIV (as per my second example).
On Apr 28, 4:49 am, gostbuster <jeremyescol...@gmail.com> wrote: > Okay everyone, I tried this : > > $('#plan').click(function(event) { > alert("click plan"); > }); > > $('#plan > .emplacement_plan').click(function(event){ > > alert("click emp"); > return false; > }); > > and it WORKS ! > > but this way is "makeshift" (=bricolage(??), not a really good and > efficient way to do?). > > ... > > On 28 avr, 09:37, gostbuster <jeremyescol...@gmail.com> wrote: > > > Hi everyone, > > > I just try this : > > > $('#plan').click(function(e){ > > if ( $(e.target).is('li') )//si on click sur un > > emplacement > > { > > alert('click on li'); > > } > > else > > { > > alert('click on plan'); > > } > > > }); > > > It seems not to work, it only alert me 'click on plan' even if I click > > on a li element.... > > > On 27 avr, 19:50, Ricardo <ricardob...@gmail.com> wrote: > > > > That's because the click event from a LI bubbles up to the DIV. Two > > > simple ways to avoid it: > > > > $('#plan').click(function(e){ > > > //abort if a LI was clicked > > > if ( $(e.target).is('li') ) > > > return false; > > > > //then do stuff() > > > > }); > > > > (alternatively use if ( e.target.id != 'plan' )) > > > > or a less efficient but explanative way: > > > > $('#plan').click(function(){ > > > //do stuff}); > > > > $('#plan li').click(function(e){ //or #plan > * > > > return false; > > > //returning false calls e.stopPropagation() and e.preventDefault > > > () > > > }); > > > > cheers, > > > - ricardo > > > > On Apr 27, 10:26 am, Remon Oldenbeuving <r.s.oldenbeuv...@gmail.com> > > > wrote: > > > > > It looks obvious, but aint working for me. > > > > > On Mon, Apr 27, 2009 at 3:16 PM, Mauricio (Maujor) Samy Silva < > > > > > css.mau...@gmail.com> wrote: > > > > > > De: "gostbuster" <jeremyescol...@gmail.com> > > > > > Assunto: [jQuery] Re: div contains <li> -> select div but NOT li > > > > > Hi, > > > > > Yes of course I could do this, but Jquery selectors don't allow what I > > > > > wish to do? > > > > > Thanks. > > > > > > ------------------------------------------------------------------------------ > > > > > How about: > > > > > $('#plan').not('ul').click(function(){...} > > > > > Maurício