With the help of Scalate's Scuery and its CSS3 selectors and transforms:
def modAttr(name: String, fn: Option[String] => Option[String])(node: Node) = node match {
case e: Elem =>
fn(e.attribute(name).map(_.toString))
.map { newVal => e % Attribute(name, Text(newVal), e.attributes.remove(name)) }
.getOrElse(e)
}
$("#foo > div[bar]")(modAttr("bar", _ => Some("hello")))
— this transforms e.g. this
into
`