Coffeescript & rightjs, Div Click
-
19-06-2021 - |
質問
I am working in sinatra, with Coffeescript and rightjs.
in the body of the html I have a div
<div id="loginimage">
<img src="/images/login.png">
</div>
and a footer element
<footer>
<div id="footer">
<form action="/login" class="login" method="post">
</form>
</div>
</footer>
and finally my coffee script looks like:
$(document).onReady ->
"#loginimage".onClick ->
"#footer".toggle "fade"
I want to be able to click on the div with id loginimage and toggle the footer element, right now I have it toggling the div with id footer, how can I select html5 elements like footer? What am I doing wrong?
解決
I'm not that familiar with RightJS but I suspect that you'd just use a normal <footer>
selector in the string:
$(document).onReady ->
"#loginimage".onClick ->
"footer".toggle "fade"
No hash (id
selector), no dot (class selector), just the element name. The String documentation for RightJS even includes things like this:
"div.something".addClass('marked');
"div#something".highlight();
so presumably the string that you're calling RightJS methods on is just any old selector.
所属していません StackOverflow