Search code examples
jquery-mobilemoovwebtritium

In Tritium, how do I add an attribute with no value assigned to it?


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?


Solution

  • 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!