[development] behaviors context
Matt
matt at aleph-null.tv
Fri May 29 19:36:28 UTC 2009
No -- the context will refer to whatever is passed into
Drupal.attachBehaviors(). In Drupal core, that will be a DOM Element
or a jQuery object. I know of no guarantee that the jQuery will always
point to one DOM element (though I know of no place in Drupal core
where more than one is passed in).
For contributed modules... I suppose you are at the liberty of the
contrib developers.
Matt
On Fri, May 29, 2009 at 2:03 PM, David Cohen <drupal at dave-cohen.com> wrote:
> So just to clarify, will the context always refer to a single element?
> In other words should my code be:
>
> $elem = $(context).get(0);
> do_my_behavior($elem);
>
> or, more like:
>
> $(context).each(function () {
> $elem = $(this).get(0);
> do_my_behavior($elem);
> });
>
>
> And in the first invocation, when context == document, will
> $(document).get(0) return the document?
>
> Thanks everyone for helping me understand.
>
> -Dave
>
>
> On Fri, 29 May 2009 11:44 -0700, "Earl Miles" <merlin at logrus.com> wrote:
>> I totally disagree. It's either a jquery object or something you can
>> easily make into a jquery object. Using $(context) should always work
>> and you can get a DOM element using $(context).get(0). Ignoring context
>> will lead to poor performance.
>
--
http://technosophos.com
http://querypath.org
More information about the development
mailing list