2

I have a normal tag:

<a href="prefetchThisPage.html"> ... </a> 

I need it to look like this:

<a href="prefetchThisPage.html" data-prefetch> ... </a> 

Why? jQuery Mobile feature: http://jquerymobile.com/demos/1.1.1/docs/pages/page-cache.html

The expected way below does not add the attribute, probably because Tritium ignores empty attributes.

attribute("data-prefetch")

Any ideas?

Serge P
  • 1,173
  • 3
  • 25
  • 39
gregorygtseng
  • 851
  • 4
  • 12

2 Answers2

2

Great Question!

The best way to do this, is to set the value of the variable to the NAME of the variable.

I would do it like this:

$variable_name = "data-prefetch"
$("./a") {
  attribute($variable_name, $variable_name)
}

This is an HTML5 convention and should work for the purposes you illustrated!

1

Tritium currently has a short circuit that converts attribute assignments like the following declaration:

attribute("data-prefetch", "")

Into the equivalent of removing the attribute.

I strongly recommend you file this issue with Moovweb's help desk so that they add support for adding attributes with no values.

Zkoh
  • 2,932
  • 3
  • 18
  • 14