That page you've linked to is mistaken (cue booing and jeering at W3Schools). The selectors listed there are jQuery selectors, many of which are non-standard. They are not valid CSS selectors, even though they use a similar syntax.
Although the :first
pseudo-class is defined for use with the @page
rule, it is not defined for use anywhere outside it. A selector like p:first
is not valid in either a style rule or a @page
rule, nor is it valid in a document.querySelectorAll()
call. Page selectors are a special type of selector that is described in this section of CSS2.1 as well as this section of the Paged Media module. While they are part of the CSS standard, they are not considered part of the Selectors standard or related standards, although, like jQuery selectors, they share a similar syntax.
While :first
is also defined in jQuery, it functions very differently in jQuery than in a @page
rule. The page you link to is obviously demonstrating jQuery's version. I would hesitate to call :first
a valid selector more so a valid page selector or a jQuery selector because it's so context-sensitive, plus it obviously can't be used in a CSS stylesheet or document.querySelectorAll()
.
Like :first
, :eq()
and their related selectors are non-standard jQuery selectors. They also function very differently to :first-child
, :nth-child()
, etc, so while you may be able to use those selectors to emulate them to some extent in CSS, they're not exactly the same (otherwise jQuery wouldn't have created the non-standard ones). See my answer to this question for an in-depth explanation.
As mentioned, :contains()
was going to be part of CSS but never made it. It's emulated in jQuery anyway, but keep in mind that it may be expensive in terms of performance and/or not work as you might expect it to.