goal
A good and final way to recall functions after something has happened.
Problem
I work with some functions that you need to remember when something happens. A simple example is a button similar to the following Twitter button.
So far, all is well. But I do not know how to remember. Actually, I already tried to use $.getScript jQuery, but it causes a lot of requests to the server, and I don’t feel comfortable with this behavior.
To illustrate the problem, I made this jsFiddle . When you hover the button for the first time, its style will change. When you click on it and click again, the "hover behavior" disappears.
I really don't know how to act.
$.getScript Is this the best solution for this?
Anyone have a suggestion?
Code (if jsFiddle down)
The knockout in the code is just an example, and it does not matter. I want to do this with ajax calls and all that is possible.
HTML:
<div class="container"> <button class="btn primary" data-bind="click: add">Add Xbox 360</button> <button class="btn btn-success primary remove" data-bind="click: remove">Xbox 360 already added</button> </div>
JavaScript:
$("button.remove").hover(function() { $(this) .removeClass("btn-success") .addClass("btn-danger") .text("Click here to remove"); }, function() { $(this) .removeClass("btn-danger") .addClass("btn-success") .text("Xbox 360 already added"); }); ViewModel = function() { var self = this; self.isAdded = ko.observable(false); self.add = function(item) { item.isAdded(false); }; self.remove = function(item) { item.isAdded(true); }; }; ko.applyBindings(new ViewModel());
source share