<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">$('#menu-user-navigation
      li:first-child', context).once('my-identifier', function(){<br>
      &nbsp; var div=$('&lt;div /&gt;').addClass('settings');<br>
      &nbsp; $(this).prepend(div);<br>
      &nbsp; div.click(function(){<br>
      &nbsp; &nbsp;&nbsp;&nbsp; if ($('#p').is(':visible')) {<br>
      &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $('#p').hide();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; } else {<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; $('#p').show();<br>
      &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>
      &nbsp;&nbsp;&nbsp; })<span class="HOEnZb"><font color="#888888"><br>
        </font></span>})<br>
      <br>
      Once you're inside the once callback function 'this' will
      reference the actual DOM element you are selecting work on
      ('#menu-user-navigation li:first-child'). The my-identifier can be
      anything. jQuery once() adds that to the element to indicate it
      has already been processed.<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 11:17 AM, Jeff Greenberg wrote:<br>
    </div>
    <blockquote
cite="mid:CAPpCgRafhX+YRwdD-FZh5rtxogF_-sbzZCrsyCcGGxFiTwP9tQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">Jamie, thanks for this, so with your 'even better'
        example, given the following, with the final line being what
        I'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>
        &nbsp; <br>
        &nbsp; Drupal.behaviors.PlaceHolders = {<br>
        &nbsp;&nbsp;&nbsp; attach: function (context, settings) {<br>
        <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(context).find('#menu-user-navigation
        li:first-child').prepend('&lt;div
        class="settings"&gt;&lt;/div&gt;');<br>
        <br>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Fri, Mar 15, 2013 at 11:07 AM, Jamie
          Holly <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:hovercrafter@earthlink.net" target="_blank">hovercrafter@earthlink.net</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF">
              <div>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>
                })<span class="HOEnZb"><font color="#888888"><br>
                    <pre cols="72">Jamie Holly
<a moz-do-not-send="true" href="http://www.intoxination.net" target="_blank">http://www.intoxination.net</a> 
<a moz-do-not-send="true" href="http://www.hollyit.net" target="_blank">http://www.hollyit.net</a></pre>
                  </font></span>
                <div>
                  <div class="h5"> On 3/15/2013 10:48 AM, Jeff Greenberg
                    wrote:<br>
                  </div>
                </div>
              </div>
              <div>
                <div class="h5">
                  <blockquote 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></fieldset>
                    <br>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            --<br>
            [ Drupal support list | <a moz-do-not-send="true"
              href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a>
            ]<br>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
    <br>
  </body>
</html>