Ticket #10070 (closed bug: worksforme)
$(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
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.