Wanna use functions, which are defined in files of coffeescript language, to change one of CSS attributes such as display when an user clicking a button or element at a web page? You can follow below instructions.
At side of web page, for example:
<button type="button" name="btn-veggie-list" class="btn-veggie-list">Veggie list</button>
<ul class="veggie-list">
<label><input type="checkbox" class="veggie-1" value="taro">芋</label>
<label><input type="checkbox" class="veggie-2" value="gherkin">小黃瓜</label>
</ul>
<label></label>
tag is used for selecting and unselecting a checkbox when we clicking text of label.
The other side for coffeescript file, for example:
display_or_not_veggie_list
.display_or_not_veggie_list = ->
current_value = $('.veggie-list').css('display') # this is a class-selector of JQuery in Coffeescript file
if current_value == "none"
$('.veggie-list').css('display', 'block')
else
$('.veggie-list').css('display', 'none')
$(document).on 'click', '.btn-veggie-list', display_or_not_veggie_list # yes, it works but it will fire many events when clicking a element, e.g. button
$(document).off('click', '.btn-veggie-list').on 'click', '.btn-veggie-list', display_or_not_veggie_list # Yes, it works and better than aboved one.
$('.btn-veggie-list').on 'click', -> display_or_not_veggie_list # no, it doesn't work. So don't use this. I've modified this example from original one at stackoverflow.com in the reference. That one doesn't work for me.
My environment is:
Reference: