I am trying to rotate an image using javascript and I was trying some code I found on adobes website that does what I was looking for. When I run it it gives me the error: Unca
When in the head
(look at the console):
http://jsfiddle.net/m2wce/
This happens because you are declaring the closure and executing right away. When you execute it in the head
, the DOM is not ready (in other words, the HTML below still hasn't been "mounted" by the browser, as it processes the page sequencially, from top to botto) and at the time of the execution the img
tag does not yet exist (because it is down below in the HTML page).
When in the body
, after the referenced img
, it works:
http://jsfiddle.net/m2wce/1/