Created
January 20, 2016 17:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$('*').removeClass(); | |
$('*').removeAttr('style'); | |
$('link[rel="stylesheet"]').remove(); | |
$('img').each(function () { | |
$(this).replaceWith( | |
$(this).attr('alt') | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 likebgcolor
, 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/