admin管理员组文章数量:1417415
Is there any alternative to JS 'innerHTML' property in CoffeeScript?
In JS, you would end up writing something like:
document.getElementById('element').innerHTML = "blah_blah"
What is the alternative to do that in CoffeeScript? I have already tried:
element = $('element')
element.html "blah_blah"
Is there any alternative to JS 'innerHTML' property in CoffeeScript?
In JS, you would end up writing something like:
document.getElementById('element').innerHTML = "blah_blah"
What is the alternative to do that in CoffeeScript? I have already tried:
element = $('element')
element.html "blah_blah"
Share
Improve this question
edited Mar 18, 2015 at 17:45
Oleg
9,3692 gold badges45 silver badges59 bronze badges
asked Mar 18, 2015 at 17:43
Rahul BhargavaRahul Bhargava
5481 gold badge7 silver badges17 bronze badges
6
-
1
CoffeeScript simply provides a different syntax to write JS. It doesn't have anything to do with the DOM API. So I guess the answer to "Is there any alternative to JS 'innerHTML' property in CoffeeScript?" is no, because that's not what CoffeeScript does. The code you posted actually looks like you are using jQuery, but with the wrong selector. Should be
$('#element')
. – Felix Kling Commented Mar 18, 2015 at 17:46 - So, you are saying that I need to do same old boring stuff again.. :) Something like: document.getElementById()... – Rahul Bhargava Commented Mar 18, 2015 at 17:47
- See my updated ment. CoffeeScript: A "language" that piles to JS. jQuery: A JS library around the DOM API. Those are two unrelated and independent things. – Felix Kling Commented Mar 18, 2015 at 17:48
- "I have already tried:" ... and what happened when you tried that? – JLRishe Commented Mar 18, 2015 at 17:51
- Looks like its just a bug in your jQuery selector: jsfiddle/xf3kgkhv/1 – Jason Sperske Commented Mar 18, 2015 at 17:54
2 Answers
Reset to default 3CoffeeScript doesn't replace or augment the DOM API. If you want to use some fancy syntax, then check out the examples below. They all do the same thing.
CoffeeScript (without jQuery):
document.getElementById('element').innerHTML = 'blah_blah'
(document.getElementById 'element').innerHTML = 'blah_blah'
document
.getElementById 'element'
.innerHTML = 'blah_blah'
CoffeeScript (with jQuery, note the # in the selector):
$('#element').html 'blah_blah'
($ '#element').html 'blah_blah'
$ '#element'
.html 'blah_blah'
There is actually an alternative to do that in coffee script.
password = $('#user_password')
message.html "Password Match"
I missed '#' selector tag in my question.
本文标签: javascriptSet innerHTML in CoffeeScriptStack Overflow
版权声明:本文标题:javascript - Set innerHTML in CoffeeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745262692a2650428.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论