EDIT
In my code I have some shorthand JS that a colleague at work helped me with. I do not entirely understand it and would be much happier changing it back to simple jQuery. I have tried to myself but it keeps breaking.
Here is the shorthand
if (target.length) {
target.addClass("occupied");
$(".occupied").parent(".flip-wrapper").addClass("flipped");
b.clone().addClass(
b.data("letter") == target.parents('td').data("letter") ? "right-letter" : "wrong-letter").appendTo("table").css({
background: "transparent",
position: "absolute",
top: currentPos.top,
left: currentPos.left
}).animate({
top: targetPos.top,
left: targetPos.left
}, "slow", function() {
$(this).css({
top: 0,
left: 0
}).appendTo(target);
I have tried to change it like this
if (target.length) {
target.addClass("occupied");
$(".occupied").parent(".flip-wrapper").addClass("flipped");
b.clone().addClass(
if $(b.data("letter") == target.parents('td').data("letter")) {
$(this).addClass("right-letter");
} else {
$(this).addClass("wrong-letter")
}.appendTo("table").css({
background: "transparent",
position: "absolute",
top: currentPos.top,
left: currentPos.left
}).animate({
top: targetPos.top,
left: targetPos.left
}, "slow", function() {
$(this).css({
top: 0,
left: 0
}).appendTo(target);
Where am I going wrong?
The main issue lies in the fact that,
addClassmethod. Please see the apihttp://api.jquery.com/addClass/
change
to just
b.clone()Since addClass cannot receive if conditions directly like this, you need to either wrap them in
function(){}or just remove the addClass thereThe working code is here
http://jsfiddle.net/Dxxmh/86/