Skip to content

Instantly share code, notes, and snippets.

@despeset
Last active December 10, 2019 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save despeset/24826d8343c3c6520707 to your computer and use it in GitHub Desktop.
Save despeset/24826d8343c3c6520707 to your computer and use it in GitHub Desktop.
Replace images that have alt attributes with their text.
Array.from(document.querySelectorAll('img[alt]:not([alt=""])')).forEach($el => {
const $div = document.createElement('div');
$div.style.display = 'inline-block';
const {width, height} = $el.getBoundingClientRect();
$div.style.width = width;
$div.style.height = height;
$div.innerText = $el.getAttribute('alt');
$el.parentNode.replaceChild($div, $el);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment