Bug Tracker

Opened 9 years ago

Closed 9 years ago

#9245 closed feature (wontfix)

An array as jQuery context argument

Reported by: silesianlordt Owned by: silesianlordt
Priority: low Milestone: 1.next
Component: core Version: 1.6rc1
Keywords: Cc:
Blocked by: Blocking:

Description

I think it should be possible to pass an array of DOM elements to jQuery() as context.

Example:

HTML:

<div id="a">
  <span class="book">
</div>
<div id="b">
  ... some html...
</div>
<div id="c">
  <span class="book">
</div>
<div id="d">
  ... some html...
</div>

JS:

var a = $('#a'),
    c = $('#c');

$('.book',[a,b]).hide();

I know there are different ways to do what I've done above. I want to show simple example.

Change History (4)

comment:1 Changed 9 years ago by silesianlordt

Sorry should be:

$('.book',[a,c]).hide();

not

$('.book',[a,b]).hide();

comment:2 Changed 9 years ago by Rick Waldron

Component: unfiledcore
Owner: set to silesianlordt
Priority: undecidedlow
Status: newpending

Isn't that the same as... $(".book").hide();

comment:3 Changed 9 years ago by ajpiano

In recent discussions, the team has been resistant to add additional signatures to the main jQuery() function. In general, the context argument is just a long-path to $(context).find("selector"), so adding additional type checking into the main jQuery function to test for an array of dom elements as CONTEXT, when an array of DOM elements is already an existing signature and you could simply do $([a,b]).find(".foo");

Also worth noting is that your example does not actually use an array of DOM elements as the context, it tries to use an array of jQuery objects as the context, which I tend to think we're even less inclined to support - as either the first or second argument to jQuery - see #9011

comment:4 Changed 9 years ago by Rick Waldron

Resolution: wontfix
Status: pendingclosed

+1

Note: See TracTickets for help on using tickets.