click event fires twice

click event fires twice

I ran inro a problem recently which i haven't found any solution to.

i generated a subnode for all unordered lists which are Childs of List-Elements like this:

  1. <ul>
  2.       <li>1</li>
  3.       <li>2
  4.             <ul>
  5.                   <li>2.1</li>
  6.                   <li>2.2</li>
  7.             </ul>
  8.       </li>
  9.       <li>3</li>
  10. </ul>

The generated list works fine and looks like this:

  • 1
  • 2
    • 2.2
    • 2.2
    • back    <-Generated Element   <li class="back">back</li>
  • 3

but if I click the Back button the Event fires twice (or the function runs twice)

  1. $("li").click(function(e){
  2. alert("in");
  3. if($(this).is('.back')) {
  4.         alert("back");
  5. }else{
  6. $(this).parent().children().hide();
  7. $(this).show();
  8. $(this).children().show();
  9.              alert("li clicked");
  10. }
  11. });
Click on back:

in
back
in
li clicked

on others:

in
li clicked


Thanks in advance
Fiisch0r