Checks if an image element has alt text
Validates that an HTMLImageElement has a non-empty alt attribute. Logs an error to console if alt text is missing.
The image element to validate
True if image has alt text, false otherwise. Returns true if image is null/undefined.
const img = document.querySelector('img');if (!imageHasAlt(img)) { // Handle missing alt text} Copy
const img = document.querySelector('img');if (!imageHasAlt(img)) { // Handle missing alt text}
Checks if an image element has alt text
Validates that an HTMLImageElement has a non-empty alt attribute. Logs an error to console if alt text is missing.