ractive template
<div class="more" on-click="more-detail">
<div class="icon-close" on-tap="close"></div>
</div>
When div is clicked, more detail shows but a bit unsure how to make div.more close by click on icon-close div.
Tried to go thru tutorial pieces for some answer, but couldn't find. I thought by using similar way as JQuery like this:
$('.more').hide();
It seems to be working - but when going back to same div and click, it took 2 times to open details again. Is it normal?
Help please.
The easiest way to achieve this is with data binding - rather than modifying the DOM manually (as with
$('.more').hide()
), put the extra detail inside a block that is only rendered when some value is truthy, and let Ractive determine when to show and hide it:That way, you never run into a situation where the DOM and your viewmodel get out of sync - for a given viewmodel state, there is guaranteed to only be one DOM state.
Here's a more complete example (click 'Run code snippet'):
The other advantage of this approach is that it keeps your DOM tidy - rather than having invisible elements in the page, Ractive only renders what you actually need.