IE8 innerHTML removes attribute quotes

When you get the innerHTML of a DOM node in IE, if there are no spaces in an attribute value, IE will remove the quotes around it.

So to over come this problem you can use the below function to replace it with Quotes again.

function iereplaceInnerHTML(obj, convertToLowerCase) {
 var zz = obj.innerHTML
     ,z = zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g);

  if (z){
    for (var i=0;i]/g;
      z[i] = z[i]
              , replacer = function(){
                  var args =;
                  return '="'+(convertToLowerCase ? args[2].toLowerCase() : args[2])+'"'+args[3];
          z[i] = z[i].replace(y[j],y[j].replace(replaceRE,replacer));
       zz = zz.replace(zSaved,z[i]);
  zz = zz.replace("colSpan=","colspan=");
  return zz;

Usage :


Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image