Rails 3.1 rc4 and Jquery: beginner's question
I'm new to jquery and i just upgraded to rails 3.1 rc4 and i'm now starting a new project.
So far i've figured i can just convert my jQuery code to coffeescript and place开发者_开发技巧 it in something.js.coffee, for example
BUT: where should i place pure jquery code?
I'm trying to get this simple example to work: http://api.jquery.com/hide/ I've tried putting the following code in application.js and home.js.coffee but nothing worked so far..
$("p").hide();
$("a").click(function ( event ) {
event.preventDefault();
$(this).hide();
});
Thanks in advance
Either of the places you've suggested (application.js or a specific coffeescript file) are valid - though it should be written in the coffee syntax if you're putting it in a coffeescript file.
You need to put that code within a $(document).ready
function to get it to work...
$(document).ready(function() {
$("p").hide();
$("a").click(function ( event ) {
event.preventDefault();
$(this).hide();
});
});
精彩评论