Image element src property does not allow URL assignment
See original GitHub issueBug Report
🔎 Search Terms
image src dom
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.3.0
⏯ Playground Link
Playground link with relevant code
💻 Code
let image = document.createElement('img');
image.src = new URL("http://google.com");
console.log(image.src)
🙁 Actual behavior
Type 'URL' is not assignable to type 'string'.(2322)
🙂 Expected behavior
Compiles cleanly (confirmed supported per https://github.com/whatwg/html/issues/6440)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top Results From Across the Web
<img>: The Image Embed element - HTML - MDN Web Docs
The src attribute is required, and contains the path to the image you want to embed. The alt attribute holds a text description...
Read more >HTML DOM Image src Property - W3Schools
The src property sets or returns the value of the src attribute of an image. The required src attribute specifies the URL of...
Read more >Overriding HTML img src assignments - Stack Overflow
I am trying to dynamically override all IMG url assigments by redefining property of Image/HTMLImage object. It correctly intercepts assignments ...
Read more >Create Image Elements in JavaScript - SoftAuthor
Create a static image tag with a src attribute with an image URL in the HTML file. ... output: As you can see,...
Read more >A 4-Minute Guide to the Img src Attribute in HTML
That reference is found in the source attribute. The source attribute contains the path to the image file or its URL. That explains...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’d want to be more permissive to a degree; letting anything in with a
toString()
seems undesirable, whereas unblocking a scenario like assigningURL
instances to ~a property calledurl
~ thesrc
property seems reasonable.It’s more subtle than that. Every DOMString or USVString will convert any input to a string. Technically, everything in JavaScript is convertible to a string, at the very least through Object.prototype.toString(). So hard-coding URL doesn’t make sense to me.