jquery - Clicking on a <li> object and excluding tags under it -


possible duplicate:
how ignore click event when clicked on children.

i wanted know how can build <li> clickable jquery while inside it, have <a href="/home"> don't want same click on rest of li do...

example :

<li>     <div> bla bla </div>     <div> <a href="/home"> </a> </div> </li> 

and jquery code :

$(document).ready(function () {     $('li').hide();      $("li").toggle(         function () {             $(this).next().show("slow");         },         function () {             $(this).next().hide();         }     ); }); 

now want toggle function not work on <a href> on rest of <li>, explain, when click on link want reach "/home"...

thanks, golan

the problem comes fact click event happens on tag bubbles happen on list item, , other elements happen in branch of dom.

the solution stop bubbling in click event on link. following should work.

$('li a').click(     function(event){         event.cancelbubble = true;         if (event.stoppropagation) event.stoppropagation();         } ); 

you return false in event above, stop browser following link.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -