RE: img name obsolete

It's not wrong. You've written obsolete code likely caused by unwittingly learning outdated methods. If you learned in a course, shame on your instructor (and ask for your money back). If you learned on a website, shame on the website for not noting the standard it's written in, but it's somewhat on the developer to be cognizant of the current standard and to code to it. You can always find the current HTML standard at https://www.w3.org/html/. Here is the documentation for the IMG element: https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element.


W3schools says: "In HTML5, the "name" attribute is deprecated and has been replaced by the "id" attribute for many elements. Use the document.getElementById()<https://www.w3schools.com/jsref/met_document_getelementbyid.asp> method where it is appropriate." ID is not deprecated, see https://html.spec.whatwg.org/multipage/indices.html#attributes-3, however, I'm not sure the rest will validate. You'll likely need to put the image into a div element and ID the divs rather than the images directly, since, as if you read the documentation I provided above, you can see that ID is not a supported attribute in the img element. This probably wouldn't be too difficult: <div ID="linked"><img src="your_image"></div>. That being said, ID is defined as follows: "The id attribute specifies its element's unique identifier (ID)", so I'm not sure if the validator is going to scream warnings at you for not making each one unique. Basically, what you are doing is...wrong. The logic is...wrong. But lots of things make us happy and we can like the results while they are technically wrong. If it works, and it makes you happy, you may as well just leave it as it is. No one really cares if your code is sloppy and deprecated these days anyway – that's how 90% of today's content creation and analytic tools generate it and there's nothing we can do about it and no one seems to care about clean code anymore, so just do whatever makes you happy on your website. If you want to take a stab at making it validate, I'd try nesting the images inside div elements and putting the ID attribute on the div elements. That's my best guess at it not actually having done this thing you're doing or seeing your code in full. Good luck.


From: Kroos, Hartmut <H.Kroos@hacofco.de>
Sent: Monday, July 12, 2021 9:39 AM - 9:39 AM
To: www-validator@w3.org
Subject: img name obsolete

This message is from an external sender. Please be careful when clicking on links and attachments.

Hi!

I enjoy using your testing procedures to eliminate all
those little bugies one can hardly find by reading.

Recently I added some eventlisteners to my code
and found out how to getElementsByName.

As my site has a number of pics, meant to call other
pages and other pics, which are for decoration only,
I named the first group with name=“linked“ and
added a listener to them, getting the action data from
the target.id.

Works nice and I am happy with the result, but your
validator specifies the name-attribute as obsolete,
which seems wrong.

Do you have any suggestions or recommendations?

Thank you,
Hartmut

Received on Wednesday, 4 August 2021 05:43:59 UTC