.
, :
$("a.xx, a.yy").click(function() {
var $this = $(this);
if ($this.hasClass("xx")) {
$this.removeClass("xx").addClass("yy");
}
else {
$this.removeClass("yy").addClass("xx");
}
});
: http://jsbin.com/ecidi3
(), :
$("a.xx, a.yy").click(function() {
var $this = $(this);
var classes = $this.hasClass("xx") ? ["xx", "yy"] : ["yy", "xx"];
$this.removeClass(classes[0]).addClass(classes[1]);
});
, live:
$("a.xx, a.yy").live("click", function() {
var $this = $(this);
if ($this.hasClass("xx")) {
$this.removeClass("xx").addClass("yy");
}
else {
$this.removeClass("yy").addClass("xx");
}
});
: http://jsbin.com/ecidi3/2 , , . , , , (), , .
, , . :
$("a.xx, a.yy").click(function() {
var $this, c;
$this = $(this);
c = $this.hasClass("xx")
? {us: "yy", them: "xx" }
: {us: "xx", them: "yy" };
$("a." + c.us).removeClass(c.us).addClass(c.them);
$this.removeClass(c.them).addClass(c.us);
});
http://jsbin.com/ecidi3/5
, , live, :
$("a.xx, a.yy").live("click", function() {
: http://jsbin.com/ecidi3/6