<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>
$(this).addClass('my-class-processed');<br>
{..LOGIC..}<br>
})<br>
<br>
For 7:<br>
<br>
$("#x", context).once('x', 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'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 = $('<div />').addClass('settings');<br>
$(this).prepend(div);<br>
div.toggle(<br>
// Odd clicks<br>
function(){<br>
$('#p').show();<br>
},<br>
// Even clicks<br>
function() {<br>
$('#p').hide();<br>
})<br>
<br>
Even better:<br>
<br>
var div = $('<div />').addClass('settings');<br>
$(this).prepend(div);<br>
div.click(function(){<br>
if ($('#p').is(':visible')) {<br>
$('#p').hide();<br>
} else {<br>
$('#p').show();<br>
}<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('<div
class="settings"></div>');<br>
$(context).find('div.settings').click(<br>
function () {<br>
$('#p').show();<br>
},<br>
function () {<br>
$('#p').hide();<br>
}<br>
);<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>