Bug Tracker

Modify

Ticket #10070 (closed bug: worksforme)

Opened 22 months ago

Last modified 20 months ago

$(selector, context) documentation clarification

Reported by: guffa@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

Description

In the documentation the context in a search has to be:

context A DOM Element, Document, or jQuery to use as context

However, a selector string also seems to work, and people use it that way, e.g.:

$('a', '.container')

The option to use a selector should be included in the documentation, or if that option is unintended and unwanted, an example on how to use a selector as context by creating a jQuery object from it, i.e.:

$('a', $('.container'))

An example where such a use would be plausible:

function getLinks(parentSelector) {
  return $('a', $(parentSelector))
}

getLinks('.container').css('color','red');

Change History

comment:1 Changed 21 months ago by dmethvin

  • Keywords needsdocs added
  • Status changed from new to closed
  • Resolution set to worksforme

People may use it that way, but should we encourage and support it? I don't see a reason to do so. $(".container a") is a lot more obvious than $("a", ".container").

Since it's a docs issue I'll close this ticket and mark it needsdocs for later discussion.

comment:2 Changed 21 months ago by anonymous

If you feel that it should not be supported, why did you close the ticket?

The code does support it, and if that is not desired, it should be changed.

comment:3 Changed 21 months ago by dmethvin

When I say "encourage and support" I mean in terms of best practices. Yes it works, and I am not advocating we change the behavior. I am simply saying it is a convoluted way of doing something so I would prefer not to encourage it.

That's why the ticket is marked needsdocs, needing discussion about documentation. There is no change required to the code, so the ticket can be closed and the documentation addressed later.

comment:4 Changed 20 months ago by addyosmani

  • Keywords needsdocs removed

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.