If Tag

The If tag allows you to hide or show any element based on the value of a boolean variable.
Sounds easy right? but you've gotta know a couple things first.
  1. Gotta have the script tag
  2. Initiate the data attribute
  3. And you also have to have a boolean variable

<body data="{show:false}">
  <button onclick="$('show = toggle(show)')">Show</button>
  <p if="show">Show = true!</p>
</body>

Show = true!


The Breakdown

By this point you've got the data tag, so all were doing is declaring the variable show with a false value.
Then you can use the onclick attribute with the function $("") to call an action on a click.

  The click event is setting the show variable to the opposite of show.
  It uses the built in toggle() function. The toggle function takes the prop of the variable and spits out the opposite.
  The fun bit is up ahead. The actual if attribute is also taking a javascript evaluation.
  This means you could run something like if="count==2", because it is just an if statement.


Congrats, you now know if statements!

[Prev] [Next]