One of the hidden gems in Meteor is the extremely granular control you have over how HTML is rendered. Blaze was designed in such a way that you can modify, add, or remove HTML element attributes dynamically without affecting anything else in the DOM! This recipe will walk you through the use of dynamic, reactive data inside element attributes.
We will use the codebase from the Creating custom components recipe, the previous recipe in this chapter. Please follow that recipe first or download the corresponding codebase.
Proceed with the following steps to use reactivity with HTML attributes:
We first need to create a new
navcolor
template. Opennavbar.html
in your[project root]/client
folder and add the following code:<template name="navcolor"> <div class="nav navbar-form navbar-right"> <input type="checkbox" id='bgCheck' checked="{{useBG}}"/> <input type="text" id='bgColor' placeholder...