Skip to content

Instantly share code, notes, and snippets.

@karlgroves
Created January 20, 2016 17:31
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 karlgroves/8880903b6687455fa7ad to your computer and use it in GitHub Desktop.
Save karlgroves/8880903b6687455fa7ad to your computer and use it in GitHub Desktop.
Strip CSS classes, style attributes, and stylesheets and replace images with their alt attributes
$(document).ready(function(){
$('*').removeClass();
$('*').removeAttr('style');
$('link[rel="stylesheet"]').remove();
$('img').each(function () {
$(this).replaceWith(
$(this).attr('alt')
);
});
});
@karlgroves
Copy link
Author

Just something I stabbed together really quickly in reaction to someone looking into tools that convert a site to text-only.

This is also a reaction to so many of the recent discussions around "overlay" products and products that create text-only versions.

This isn't production-ready. Also, to be truly robust I suppose it would have to replace <font> tags and other deprecated elements with <span> elements, and remove presentational attributes like bgcolor, etc.

Furthermore I don't consider this to be an effective approach to accessibility.
Please read: http://www.karlgroves.com/2011/12/28/text-only-is-not-accessible/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment