« Return to Thread: behaviors context

behaviors context

by David Cohen-8 :: Rate this Message:

Reply to Author | View in Thread

I'm trying to implement a Drupal.behavior.  I realize my behavior
function is passed a "context".  But it's unclear to me what that
context will be.

If I understand correctly, when the behavior is first invoked, it is
passed document, a variable built into javascript.

Later, when some module's javascript adds content to the page, my
behavior will be invoked again.  This time, context could be anything.
The module which added the content can pass whatever.  So for example in
ahah.js, Drupal.attachBehaviors() is passed a jquery object representing
the new content.  While in modules/views/js/ajax.js,
Drupal.attachBehaviors() is passed a string or id, either of which could
be used in a jquery selector.

Do I have this right?

What I need is the javascript element (not jquery object) that is the
added content.  Does anyone have a snippet of code which returns this,
given a context?

Thanks, -Dave

 « Return to Thread: behaviors context