It's a little confusing, but the difference is that the "contextual selector" is a second argument, whereas the "or selector" is a comma within a single argument. So, if we forget about "this" for a moment:

$('.myclass, #myid')
-- matches all elements that have a class of "myclass" or id="myid"
-- both selectors are contained within the same argument (i.e. the same set of quotation marks)

$('.myclass', '#myid')
-- matches all elements that have a class of "myclass" and are descendants of an element with id="myid"
-- two arguments.


One way to include "this" in the selection would be to use .add(). For example:

$(this).add('div');
-- select this and all div elements.

Hope that helps.

--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Oct 17, 2009, at 10:40 PM, lampy wrote:


I know Karl's answer is correct, but from the docs (
http://docs.jquery.com/Selectors/multiple#selector1selector2selectorN
) I would've thought the comma meant "select all div elements, and
this".

Is there any documentation that would help me understand this?


On Sep 29, 10:03 pm, MorningZ <morni...@gmail.com> wrote:
oops... that'll teach me to try to make sense first thing in the
morning  :-)

Coffee first THEN post

On Sep 29, 9:11 pm, Karl Swedberg <k...@englishrules.com> wrote:

On Sep 29, 2009, at 7:33 AM, MorningZ wrote:

Whatever "this" is in that case, it's the context to look for any
<div> (jQuery will only select <div>'s that are ancestors of "this" in
the DOM tree)

Correction: for $('div',this), jQuery will only select <divs>s that
are descendants of "this" in the DOM tree.

--Karl

____________
Karl Swedbergwww.englishrules.comwww.learningjquery.com

Reply via email to