I am trying to change the background image in the body tag in my Rails app. I have tried it from items.js.coffee (I have table called items) and from application.js. I cant make it work from either.
I have tried to change the background color, and thats working from application.js but not from items.js.coffee.
So my question is: How can I change the background image and must all changes in CSS be done from application.js?
items.js.coffee:
$ ->
$(document).ready ->
if something
$("body").css "background-image", "url(rails.png)"
bootstrap_and_overrides.css.less:
body {
padding-top: 60px;
background-color: black;
background-image:url('HypeTrans.png');
background-repeat:no-repeat;
background-attachment:fixed;
background-position: 50% 50%;
}
<body>tag when loading the "items" page when your code is in eitherapplication.jsoritems.js.coffee, but you cannot change the background image when the code (otherwise the same) is initems.js.coffee? It is definitely not the case that CSS operations need to be done fromapplication.js, only that the JS doing the change is executed during (or more commonly) after page load.$ ->and$(document).ready ->are the same thing, you don't need both.$ ->the same as$(function(){?