What are the advantages / disadvantages of the two different selectors?
Should I use one over the other?
What are the advantages / disadvantages of the two different selectors?
Should I use one over the other?
I think it's primarily a matter of user preference.
To select the first child of all <p>
elements, you'd do:
$("//p/*[1]")
in Xpath$$("p > *:first-child")
in CSSI prefer using Xpath, but YMMV.
Note that, internally, all CSS selectors are converted to Xpath. For example, the selector $$("#one")
will be converted into $(".//*[id='one']")
.
Just a few notes:
//p/*[1]
>
, as in $$("> p > :first-child")
; this will be converted into a scoped search (i.e., ./p/*[1]
)