Reputation: 277
I would hide an html element when a condition occurs. I try to implement this code in coffeescript:
if byName == username
document.#prv-btn.style.display = 'none'
I have already tried this code but don't run.
The element #prv-btn
is my html element. In my page i have some users and for each of them i have this #prv-btn
. For example if i have ten users, i have ten #prv-btn
, but only one i want that i see, each user see the button near his name.
How can I do?
Upvotes: 0
Views: 1093
Reputation: 5547
There are a couple of issues:
if
clauses in CoffeeScript.getElementById()
to actually select the button
by its ID.Also, I recommend using jQuery for DOM work such as this. It works just fine with the compiled CoffeeScript.
Code:
if byName == username
document.getElementById("prv-btn").style.display = 'none'
Here is a link to a jsFiddle that I made for this: http://jsfiddle.net/jonathanporta/tw3nn/1/
Upvotes: 3