Attempting to randomly assign values to an image's left
and right
properties using JQuery. Here is the code snippet:
var sides = ["left", "right"]
var currentSide = sides[Math.floor(Math.random() * sides.length)];
$("#"+currentImage).css({currentSide : "80px"});
An array called 'sides' holds either 'left' or 'right', with one being randomly selected to set the CSS property of the element to either right: "80px";
or left: 80px;
However, this implementation is not functioning as expected. Manually setting it e.g.
$("#"+currentImage).css({"left" : "80px"});
works fine, indicating that passing variables to the .css()
function may be causing the issue.
Any suggestions on how to resolve this?