Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

TagsToLowerCase

DZone's Guide to

TagsToLowerCase

·
Free Resource
// From shauninman.com  - Given an HTML string with uppercase tags and attributes and mixed case attribute values and tag contents, return that string with lowercased tags and attributes but leave the attribute values and tag contents alone. (Certain browsers return the innerHTML of elements in this malformed way—which can be a problem if the source is headed to a textarea and ultimately saved to a database.)


function tagsToLowerCase(html)
{
    html = html.replace(/([a-z])\s*(=)\s*("|')/gi, '$1$2$3');
    var parts = html.match(/(<\/?[a-z][a-z0-9]*| [a-z]+=)/gi);
    for (var i = 0; i < parts.length; i++)
    {
        var part = parts[i];
        html = html.replace(new RegExp(part, 'g'), part.toLowerCase());
    }
    return html;
}
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}