RIOT.JS Tutorial
Selected Reading
- RIOT.JS - Discussion
- RIOT.JS - Useful Resources
- RIOT.JS - Quick Guide
- RIOT.JS - Observables
- RIOT.JS - Mixin
- RIOT.JS - Loops
- RIOT.JS - Accessing DOM
- RIOT.JS - Event Handling
- RIOT.JS - Yield
- RIOT.JS - Conditional
- RIOT.JS - Styling
- RIOT.JS - Expressions
- RIOT.JS - Tags
- RIOT.JS - First Application
- RIOT.JS - Environment Setup
- RIOT.JS - Overview
- RIOT.JS - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
RIOT.JS - Conditional
RIOT.JS - Conditional
Conditionals are constructs which are used to show/hide elements of RIOT tags. Following are the three conditionals RIOT supports −
if − add/remove element based on value passed.
<custom2Tag> <h2 if = {showMessage}>Using if!</h2> <script> this.showMessage = true; </script> </custom2Tag>
show − shows an element using style = "display: " if passed true.
<custom2Tag> <h2 show = {showMessage}>Using show!</h2> <script> this.showMessage = true; </script> </custom2Tag>
hide − hides an element using style = "display: none " if passed true.
<custom2Tag> <h2 show = {showMessage}>Using show!</h2> <script> this.showMessage = true; </script> </custom2Tag>
Example
Following is the complete example.
custom2Tag.tag
<custom2Tag> <h2 if = {showMessage}>Using if!</h2> <h2 if = {show}>Welcome!</h1> <h2 show = {showMessage}>Using show!</h2> <h2 hide = {show}>Using hide!</h2> <script> this.showMessage = true; this.show = false; </script> </custom2Tag>
custom2.htm
<!DOCTYPE html> <html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/pbs/riot/3.13.2/riot+compiler.min.js"></script> </head> <body> <custom2Tag></custom2Tag> <script src = "custom2Tag.tag" type = "riot/tag"></script> <script> riot.mount("custom2Tag"); </script> </body> </html>
This will produce following result −
Advertisements