brian-watkins/elm-spec/1.1.0

NOTE: the latest version is 3.3.2

Spec.Markup.Selector

Build abstract descriptions that can be used to select aspects of an HTML document.

Build Selectors

type Selector a

An abstract description of some aspect of an HTML document, usually an HTML element.

type Element

A kind of selector that pertains only to HTML elements.

by : List Characteristic -> a -> ( Selector Element, a )

Generate a selector that matches HTML elements with the given characteristics.

Generate a selector that matches HTML elements descending from any HTML elements with the given characteristics.

For example,

descendantsOf [ tag "div" ] << by [ tag "span" ]

will match all <span> that are inside a <div>. You may chain descendantsOf selectors using << but the chain must terminate with a by selector.

type Object

A kind of selector that pertains only to a specific item.

document : Context model -> ( Selector Object, Context model )

Generate a selector that matches the HTML document.

This is used primarily in conjunction with Spec.Markup.target to trigger document-level events.

For example,

Spec.when "a document level mouse click is triggered"
  [ Spec.Markup.target << document
  , Spec.Markup.Event.click
  ]

The document selector only works with Spec.Markup.target, which is to say that you cannot observe the document to make claims about it.

toString : Selector a -> String

Convert a Selector to a string.

For those selectors of type Selector Element, the resulting string will be in the style of a CSS selector.

Define Characteristics

A selector is built from one or more characteristics.

id : String -> Characteristic

Generate a characteristic that belongs to elements having an id attribute with the given value.

tag : String -> Characteristic

Generate a characteristic that belongs to elements having the given tag name.

For example,

tag "div"

applies to HTML <div> elements.

attribute : ( String, String ) -> Characteristic

Generate a characteristic that belongs to elements with the given (name, value) pair.

For example,

attribute ( "data-some-attr", "some-value" )

applies to elements having an attribute named data-some-attr with the value some-value.

Generate a characteristic that belongs to elements with the given attribute.

For example,

attributeName "data-some-attr"

applies to elements having an attribute names data-some-attr.