Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on positional selectors #125

Open
dmethvin opened this issue Dec 1, 2015 · 8 comments
Open

Warn on positional selectors #125

dmethvin opened this issue Dec 1, 2015 · 8 comments

Comments

@dmethvin
Copy link
Member

dmethvin commented Dec 1, 2015

See discussion in jquery/sizzle#293 . They aren't being removed in jQuery 3.0 but we should warn since they are being deprecated.

@dmethvin dmethvin added this to the 3.0.0 milestone Dec 1, 2015
@dmethvin
Copy link
Member Author

Can we move this back from the 3.0.0 milestone? Potentially it could still be removed in core 4.0 but I'm concerned that there will be a lot of noise from Migrate in real-world code, especially plugins.

@mgol
Copy link
Member

mgol commented Mar 29, 2016

It should be fine. We may very well deprecate more stuff in jQuery 3.1.0
etc. and Migrate updates will be needed to handle those deprecations. If
there's no time for this now, I'm good with postponing.

Michał Gołębiowski

@dmethvin dmethvin modified the milestones: 3.1.0, 3.0.0 Mar 29, 2016
@dmethvin
Copy link
Member Author

dmethvin commented Sep 26, 2016

For reference, the positional selectors are here along with the recommendation of alternatives. I think this full discussion will end up being big enough that it belongs in a wiki page rather than the warnings document, since there are subtle differences with the alternatives due to counting (0-base for jQuery positional selectors) and the fact that -child selectors don't apply to the entire jQuery set.

jQuery selector Alternative
:even .even() method or :nth-child(odd)
:odd .odd() method or :nth-child(even)
:first .first() method or :first-child
:last .last() method or :last-child
:eq() .eq() method
:gt(n) .slice(n+1)
:lt(n) .slice(0, n)

@stof
Copy link

stof commented Apr 12, 2019

These are now announced as deprecated in jQuery 3.4.0: https://blog.jquery.com/2019/04/10/jquery-3-4-0-released/
So warning about them would be great.

@stof
Copy link

stof commented Apr 12, 2019

@dmethvin do .gt() and .lt actually exist ? api.jquery.com does not seem to list them, AFAICT.

@dmethvin
Copy link
Member Author

@stof Oh true, you'd need to use .slice(). I've updated the comment. There used to be an .lt() and .gt() but it was deprecated long ago when .slice() arrived and removed in 1.2.

@timmywil
Copy link
Member

timmywil commented Apr 15, 2019

:first-child, :last-child, and :nth-child while they work when all of the elements have the same parent are technically not functionally equivalent (edit: I see you already noted this). The methods are the right choice.

Also, we don't have .even or .odd. I don't know if there's a clear replacement for those. Maybe we should add them in 4.0?

@dmethvin
Copy link
Member Author

Wow, I could have sworn we had those, I think we did long ago. It's trivial to add .even and .odd, either ourselves or by showing the code in the migration guide, but in many cases :nth-child or :nth-of-type do the trick in a selector as long as you're aware of the 0 vs. 1 offset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants