What is wrong with this function?
function moveColor()
{
document.getElementById(purple).style.marginRight = "34px";
}
with this html:
<div><img src="images/purple.png" id="purple" onclick="colorpurple()" onmouseover="moveColor()" style="cursor:pointer;"/></div>
I also wanted to have it move over a period of 1 second, but can’t seem to solve this simple problem.
You need to put the id in quotes (so that it is treated as a string).
The current usage means that
purplerefers to a variable, which is not defined so it has anundefinedvalue and so thedocument.getElementByIdmethod returns nothing..