Reputation: 87
please take a look at this jsfiddle: click
(function() {
var variable = {
body : $('body'),
bg: function() {
body.css('background', 'green')
}
};
})();
the console doesn't give back any error.
an short explanation would be great whats wrong here!
Thanks!
Upvotes: 0
Views: 35
Reputation: 582
Look at: http://jsfiddle.net/g3r01zmr/
(function() {
var variable = {
body : $('body'),
bg: function() {
this.body.css('background', 'green')
}
};
variable.bg()
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You have to call the function, you only have defined it so far. Also you have to use this
for the body
variable, because it is not a local variable.
Upvotes: 1
Reputation: 2814
You don't call bg
.
You can do:
(function() {
var variable = {
body : $('body'),
bg: function() {
this.body.css('background', 'green')
}
};
variable.bg();
})();
http://jsfiddle.net/13dvxsnf/1/
Upvotes: 1