Rivets.js if binder function call

1.6k Views Asked by At

I was attempting to use the default binder that comes with rivets.js , if and unless and wanting to evaluate return value from a dom element.

HTML

<div id="elem" custom-attribute="false">
    <h1 rv-if="testing.getAttribute('custom-attribute')">Testing </h1>
</div>

JS

rivets.bind(document, testing: document.getElementbyId(elem);

What is the best way to access a custom boolean attribute from a dom element to evaluate for a rivets if binder? Do I have to implement a custom binder?

I also did this but I hear that this is very frowned upon practice

document.getElementbyId("elem").customAttr=false;
rivets.bind(document, testing: document.getElementbyId(elem);

and then in the HTML

 <div id="elem" custom-attribute="false">
    <h1 rv-if="testing.customAttr">Testing </h1>
</div>

the below approach works, but what exactly is the con to setting attributes on an element in this manner and what is the best way to use data attributes the standard way with rivets default if and unless binders>

0

There are 0 best solutions below