img.naturalWidth
bearbeitet von
@@wonk
> ~~~ html, bad
> <img src="meinBild.jpg" name= "Bild">
> <script type="text/javascript" >
> Bildobjekt = document.getElementsByName("Bild");
> alert(Bildobjekt.naturalWidth);
> </script>
> ~~~
Ich wusste gar nicht, dass ein `img`-Element ein `name`-Attribut haben kann. Mal in die [Spec](https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element) geschaut: Kann’s auch gar nicht. Der [Validator](https://validator.w3.org/nu) meint dazu: *Error: The `name` attribute on the `img` element is obsolete.*{:@en}
Ah, das gab’s irgendwann mal; deshalb geht auch `getElementsByName()` hier (noch). Da Browser i.a.R. abwärtskompatibel sein wollen, würde ich nicht erwarten, dass sie das bald nicht mehr unterstützen, aber verlassen würde ich micht auch nicht darauf.
Der Validator weiter: *Use the `id` attribute instead.*{:@en} Genau das hätte ich auch gesagt. Und `getElementById()` hat kein s drin. (`querySelector()` auch nicht – sondern ein S. 😉)
🖖 Live long and prosper
{:@en}
--
*“In my home, the America I love, the America I've written about, that has been a beacon of hope and liberty for 250 years, is currently in the hands of a corrupt, incompetent and treasonous administration. Tonight, we ask all who believe in democracy and the best of our American spirit, to rise with us, raise your voices against authoritarianism, and let freedom reign.”*{:@en}
— Bruce Springsteen, Manchester 2025-05-14
img.naturalWidth
bearbeitet von
@@wonk
> ~~~ html, bad
> <img src="meinBild.jpg" name= "Bild">
> <script type="text/javascript" >
> Bildobjekt = document.getElementsByName("Bild");
> alert(Bildobjekt.naturalWidth);
> </script>
> ~~~
Ich wusste gar nicht, dass ein `img`-Element ein `name`-Attribut haben kann. Mal in die [Spec](https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element) geschaut: Kann’s auch gar nicht. Der [Validator](https://validator.w3.org/nu) meint dazu: *Error: The `name` attribute on the `img` element is obsolete.*{:@en}
Ah, das gab’s irgendwann mal; deshalt geht auch `getElementsByName()` hier (noch). Da Browser i.a.R. abwärtskompatibel sein wollen, würde ich nicht erwarten, dass sie das bald nicht mehr unterstützen, aber verlassen würde ich micht auch nicht darauf.
Der Validator weiter: *Use the `id` attribute instead.*{:@en} Genau das hätte ich auch gesagt. Und `getElementById()` hat kein s drin. (`querySelector()` auch nicht – sondern ein S. 😉)
🖖 Live long and prosper
{:@en}
--
*“In my home, the America I love, the America I've written about, that has been a beacon of hope and liberty for 250 years, is currently in the hands of a corrupt, incompetent and treasonous administration. Tonight, we ask all who believe in democracy and the best of our American spirit, to rise with us, raise your voices against authoritarianism, and let freedom reign.”*{:@en}
— Bruce Springsteen, Manchester 2025-05-14