I would like to hide or show an element on page load depending on the value of another element, "#init-like".
if $('span[id^="init-like"]').html() == "true"
$(this).parent().find('span[id^="like-click"]').hide()
It wasn't working, and so while troubleshooting, I had it hide or show on a click. That worked.
$('span[id^="init-like"]').click ->
if $(this).html() == "true"
$(this).parent().find('span[id^="like-click"]').hide()
I think I'm missing something basic here, because I don't see why it won't work on page load. I have successfully hidden other elements on page load, but not conditionally on anything else.
If it's relevant, the top and bottom of my coffeescript are like this which helps turbolinks and jquery to work together:
ready = ->
$(document).ready ->
####
$(document).ready(ready)
$(document).on('page:load', ready)
My overall goal is to get the "like" button to show if an item has not been liked; and for it to be hidden if an item has been liked; and vice versa with the "unlike" button.
Please let me know if more code snippets would be helpful.
Edit: The code is in a partial, so I have to make sure the coffeescript doesn't apply only the first instance.