Unfortunately, that won't work because of the way CSS selectors work in Tritium.
According to the spec, CSS selectors are converted into XPath local searches, which means they are scoped.
html() {
$("/html") {
$$("#header > img") {
add_class("logo")
}
$$("#content") {
$("./div[@id='courses']"){
$$("a") {
attribute("href", "http://console.moovweb.com/learn/training/getting_started/generate")
}
copy_to(css('#header'), "before")
}
}
}
}
In your example, your copy_to
function is in the scope of $("./div[@id='courses']")
, so it won't find the div#header
in there.
You'll have to use an XPath selector like this: copy_to("/html/body/div[@id='header']","before")
See here: http://tester.tritium.io/5f0ae313a4f43038ee4adeb49b81236bfbc5f097