<script>
alert('first');
var fileinput = document.getElementsByTagName('img');
setAttributes(fileinput, {'onchange':'preview()'});
alert('second')
</script>
<div>
<img id="preview" src="" >
</div>