Reputation: 61
I am trying to learn jQuery plugin development for a new internship at my university.
I have been messing around trying to build a plugin that gives an element a random background color when clicked.
It works when simply called, i.e.
$("#test").click(randomBackground);
but when I try to call it with a click, I can't get it to work.
Here is my jsFiddle. http://jsfiddle.net/theluigi/yTy3C/18/
Upvotes: 0
Views: 596
Reputation: 1466
Another version....
randomize = function () {
var randomBackground = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
$(this).css("background-color", randomBackground);
};
$("#test").click(randomize);
Upvotes: 0
Reputation: 11807
This worked for me.
$("#test").on('click', function(){$(this).randomize()});
Upvotes: 2