<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">First off, you really should use one of
      the once methods, which is different depending on if you're in
      Drupal 6 or 7. 6 actually doesn't have that method, but rather you
      add a class indicating it's been processed:<br>
      <br>
      $("#x:not(.my-class-processed)", context).each(function(){<br>
      &nbsp; $(this).addClass('my-class-processed');<br>
      &nbsp;{..LOGIC..}<br>
      })<br>
      <br>
      For 7:<br>
      <br>
      $("#x", context).once('x', function(){<br>
      &nbsp;{..LOGIC..}<br>
      <br>
      })<br>
      <br>
      That prevents the settings div and handler from getting added
      multiple time during different ajax calls that might fall within
      the same context. <br>
      <br>
      For your logic, it looks like you're confusing .click() with
      .toggle(). Click responds to every click and only takes a single
      callback. Toggle() takes 2 callbacks, one that is fired on odd
      clicks and one that is fired on even.<br>
      <br>
      var div = $('&lt;div /&gt;').addClass('settings');<br>
      $(this).prepend(div);<br>
      div.toggle(<br>
      &nbsp;// Odd clicks<br>
      &nbsp; function(){<br>
      &nbsp;&nbsp;&nbsp; $('#p').show();<br>
      &nbsp; },<br>
      &nbsp; // Even clicks<br>
      &nbsp;function() {<br>
      &nbsp;&nbsp;&nbsp; &nbsp; $('#p').hide();<br>
      })<br>
      <br>
      Even better:<br>
      <br>
      var div = $('&lt;div /&gt;').addClass('settings');<br>
      $(this).prepend(div);<br>
      div.click(function(){<br>
      &nbsp; if ($('#p').is(':visible')) {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $('#p').hide();<br>
      &nbsp;&nbsp; } else {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $('#p').show();<br>
      &nbsp;&nbsp; }<br>
      })<br>
      <pre class="moz-signature" cols="72">Jamie Holly
<a class="moz-txt-link-freetext" href="http://www.intoxination.net">http://www.intoxination.net</a> 
<a class="moz-txt-link-freetext" href="http://www.hollyit.net">http://www.hollyit.net</a></pre>
      On 3/15/2013 10:48 AM, Jeff Greenberg wrote:<br>
    </div>
    <blockquote
cite="mid:CAPpCgRa4J9PUS1sFdw8sjTjNSYbkA1i_G+KoS=cXBU__OM21sg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>I have the following in Drupal.behaviors:<br>
          <br>
          $(context).find('#x').prepend('&lt;div
          class="settings"&gt;&lt;/div&gt;');<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(context).find('div.settings').click(<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function () {<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $('#p').show();<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function () {<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $('#p').hide();<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>
        </div>
        The div gets prepended, but the click does nothing. If I just
        enter the jQuery('#p').show() in the console, it works fine.<br
          clear="all">
        <div>
          <div><br>
            -- <br>
            ---
            <div><a moz-do-not-send="true"
                href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div>
            <div><a moz-do-not-send="true"
                href="http://linkedin.com/in/jeffrgreenberg"
                target="_blank">linkedin.com/in/jeffrgreenberg</a></div>
            <div><a moz-do-not-send="true"
                href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a>
              / <a moz-do-not-send="true" href="http://ayendesigns.com"
                target="_blank">ayendesigns.com</a></div>
            <div>@accidentalcoder</div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
    <br>
  </body>
</html>