Selectors.Rmd
Selectors are descriptions of HTML entities on a page. Combined with a list of property/value pairs, they define which elements a particular style applies to.
Selectors may just be given as a character string, but you can also use the Selector
R6 class to help build selectors with a more complex specification.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# All things with id = 'greg' with class = 'brady'
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
myselector <- Selector$new()
myselector$class('brady')
myselector$id('greg')
myselector
#> #greg.brady
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# All 'cindy' IDs which are children of 'carol' classes, and 'bobby' IDs which
# are the last child of 'mike' classes
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parent1 <- css_sel(".carol")$
parent_of('#cindy')
parent2 <- css_sel()$
class('mike')$
attr(job = 'architect')$
parent_of(
css_sel()$id('bobby')$pseudo_class(last_child = TRUE)
)
parent1$and(parent2)
parent1
#> .carol > #cindy, .mike[job="architect"] > #bobby:last-child