The required src attribute specifies the URL of an image. Note: The src property can be changed at any time. However, the new image inherits the height and width attributes of the original image, if not new height and width properties are specified.
To change the source or src of an image, you need to add an id or class to the image tag. You can get the image element using the name of the id or class , and you can change the source or src of the image using the src property.
We can use the onerror attribute on the image to set a fallback. We use the onerror to set the error to null and set the src of the image to a fallback.
To clear an image src attribute: Use the setAttribute() method to set the image's src attribute to an empty string. Alternatively, hide the image element.
I've been looking at Javascript that can change the src of an image. I'm simply wondering if this can be done before the browser attempts to fetch the original image.
Example.
Src="Large-Image"
Can I (with javascript, I would imagine.. node.JS maybe?) serve the user src="smaller-image"
?
Obviously, there would be no performance gain if the browser loads the large image first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With