You can create a JavaScript global in your Visualforce (where URLFOR
etc works):
<script>
var closeIconUrl = "{!URLFOR($Resource.EasyResources, 'images/closeIcon.png')}";
</script>
and then use jQuery in some later JavaScript that is included in the page from a static resource to set that value as the image src
:
$j('img.canceluploadicon').attr('src', closeIconUrl);
A related technique, not requiring a change in the Visualforce, is to hard code the URL format that is output by URLFOR
and use the current time to ensure that the latest version of the static resource is used (though this will likely stop that resource being cached by the browser);
$j('img.canceluploadicon').attr(
'src',
'/resource/' + Date.now() + '/EasyResources/images/closeIcon.png'
);