I am trying to make a similar behavior as the comment link on a question in Stack Overflow. A click should hide the div containing the "Add comment" link and show another div containing the form for a new comment.
How is it possible to do that with coffeescript ?
I am trying the following that does not work :
jQuery ->
hide_comment_link = () ->
$('#add_comment_link').hide
hide_comment = () ->
$('#add_comment').hide
show_comment = () ->
$('#add_comment').show
$('#add_comment_link').click ->
hide_comment_link
show_comment
false
View is :
#add_comment_link
#{link_to "Add a comment"}
#add_comment
Add a comment in this div.
Unlike Ruby, CoffeeScript doesn't allow you to omit parentheses from function/method calls if there are no arguments. You need to add them:
$('#add_comment_link').hide()
hide_comment_link()
The do
keyword is another option:
do $('#add_comment_link').hide
do hide_comment_link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With