The following JavaScript code works perfectly in WebKit-based browsers, but it doesn't work in Firefox:
canvas.style['left'] = "50%";
canvas.style['margin-left'] = "-" + (width / 2) + "px";
Inspecting the element in Firefox, I can see that the left
property was successfully set by the above code, but the element has no margin-left
property for some reason.
It seems I must be doing something wrong, which isn't surprising, because I haven't been able to figure out what the correct way to access (read or set) CSS style properties from JavaScript is. I've just found some examples using this notation and tried to follow them, with these mixed results.
What is the correct / standards-compliant way to access an element's CSS style properties from JavaScript?