Given your code, output.realsrc
sets a property called "realsrc", not an attribute.
To set an attribute, use JavaScript's setAttribute()
.
var reader = new FileReader();
var file = document.getElementById('file');
var output = document.getElementById('output_image');
reader.onload = function() {
output.setAttribute('realsrc', this.result);
console.log(output.getAttribute('realsrc'));
}
file.addEventListener('change', function() {
reader.readAsDataURL(this.files[0]);
});
<input type="file" id="file">
<img id="output_image">
Note that:
... when an element has id or another standard attribute, the corresponding property gets created. But that doesn’t happen if the attribute is non-standard. -- HTML attributes.
Also see:
Javascript for adding a custom attribute to some elements.