Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
KnockoutJS Web Development

You're reading from   KnockoutJS Web Development Efficiently work with data, web templates, and custom HTML tags using KnockoutJS

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781782161028
Length 178 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Farrar John Farrar
Author Profile Icon John Farrar
John Farrar
Arrow right icon
View More author details
Toc

Conditional binding

Data binding is the essence of many new libraries that interact with the HTML markup as it gets converted to the DOM. We saw binding in Chapter 1, Getting Started with KnockoutJS, using the data-bind ="..." bindings. Here we will be looking at conditional binding.

The first thing we will do is understand the concept of conditional binding. Our example is meant to be conceptual. We will show a more practical example shortly in this chapter.

The if binding plays a very similar role to the visible property in the DOM. The difference is that the if binding actually adds and removes the content from the DOM whereas visible swaps the CSS display style between visible and none.

Create a new file by copying the _base.htm file, located in the ko_2/do folder, and naming it condition.htm within the do folder. If you get stuck, there is a completed copy inside the done folder. To make things look better, we will now be using the larger Bootstrap template base as it will...

You have been reading a chapter from
KnockoutJS Web Development
Published in: Feb 2015
Publisher:
ISBN-13: 9781782161028
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image