<div dir="ltr">I should add that this was existing code, and worked until I added the prepend and changed the click to be for the newly prepended div instead of one that was already present.<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Mar 15, 2013 at 11:17 AM, Jeff Greenberg <span dir="ltr">&lt;<a href="mailto:listmail.ayendesigns@gmail.com" target="_blank">listmail.ayendesigns@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Jamie, thanks for this, so with your &#39;even better&#39; example, given the following, with the final line being what I&#39;ll change to your line beginning var div =, what would I do with the rest of the wrapping to change it to the .once() methodology?<br>

<br>(function ($) {<br>  <br>  Drupal.behaviors.PlaceHolders = {<br>    attach: function (context, settings) {<br><br>      $(context).find(&#39;#menu-user-navigation li:first-child&#39;).prepend(&#39;&lt;div class=&quot;settings&quot;&gt;&lt;/div&gt;&#39;);<br>

<br></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Fri, Mar 15, 2013 at 11:07 AM, Jamie Holly <span dir="ltr">&lt;<a href="mailto:hovercrafter@earthlink.net" target="_blank">hovercrafter@earthlink.net</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>First off, you really should use one of
      the once methods, which is different depending on if you&#39;re in
      Drupal 6 or 7. 6 actually doesn&#39;t have that method, but rather you
      add a class indicating it&#39;s been processed:<br>
      <br>
      $(&quot;#x:not(.my-class-processed)&quot;, context).each(function(){<br>
        $(this).addClass(&#39;my-class-processed&#39;);<br>
       {..LOGIC..}<br>
      })<br>
      <br>
      For 7:<br>
      <br>
      $(&quot;#x&quot;, context).once(&#39;x&#39;, function(){<br>
       {..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&#39;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 = $(&#39;&lt;div /&gt;&#39;).addClass(&#39;settings&#39;);<br>
      $(this).prepend(div);<br>
      div.toggle(<br>
       // Odd clicks<br>
        function(){<br>
          $(&#39;#p&#39;).show();<br>
        },<br>
        // Even clicks<br>
       function() {<br>
            $(&#39;#p&#39;).hide();<br>
      })<br>
      <br>
      Even better:<br>
      <br>
      var div = $(&#39;&lt;div /&gt;&#39;).addClass(&#39;settings&#39;);<br>
      $(this).prepend(div);<br>
      div.click(function(){<br>
        if ($(&#39;#p&#39;).is(&#39;:visible&#39;)) {<br>
              $(&#39;#p&#39;).hide();<br>
         } else {<br>
              $(&#39;#p&#39;).show();<br>
         }<br>
      })<span><font color="#888888"><br>
      <pre cols="72">Jamie Holly
<a href="http://www.intoxination.net" target="_blank">http://www.intoxination.net</a> 
<a href="http://www.hollyit.net" target="_blank">http://www.hollyit.net</a></pre></font></span><div><div>
      On 3/15/2013 10:48 AM, Jeff Greenberg wrote:<br>
    </div></div></div><div><div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>I have the following in Drupal.behaviors:<br>
          <br>
          $(context).find(&#39;#x&#39;).prepend(&#39;&lt;div
          class=&quot;settings&quot;&gt;&lt;/div&gt;&#39;);<br>
                $(context).find(&#39;div.settings&#39;).click(<br>
                  function () {<br>
                    $(&#39;#p&#39;).show();<br>
                  },<br>
                  function () {<br>
                    $(&#39;#p&#39;).hide();<br>
                  }<br>
                );<br>
        </div>
        The div gets prepended, but the click does nothing. If I just
        enter the jQuery(&#39;#p&#39;).show() in the console, it works fine.<br clear="all">
        <div>
          <div><br>
            -- <br>
            ---
            <div><a href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div>
            <div><a href="http://linkedin.com/in/jeffrgreenberg" target="_blank">linkedin.com/in/jeffrgreenberg</a></div>
            <div><a href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a>
              / <a href="http://ayendesigns.com" target="_blank">ayendesigns.com</a></div>
            <div>@accidentalcoder</div>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
    </blockquote>
    <br>
  </div></div></div>

<br></div></div><span class="HOEnZb"><font color="#888888">--<br>
[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br></font></span></blockquote></div><div class="im"><br><br clear="all"><br>-- <br>---<div><a href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div>

<div><a href="http://linkedin.com/in/jeffrgreenberg" target="_blank">linkedin.com/in/jeffrgreenberg</a></div><div><a href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a> / <a href="http://ayendesigns.com" target="_blank">ayendesigns.com</a></div>

<div>@accidentalcoder</div>
</div></div>
</blockquote></div><br><br clear="all"><br>-- <br>---<div><a href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div><div><a href="http://linkedin.com/in/jeffrgreenberg" target="_blank">linkedin.com/in/jeffrgreenberg</a></div>
<div><a href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a> / <a href="http://ayendesigns.com" target="_blank">ayendesigns.com</a></div><div>@accidentalcoder</div>
</div>