Quantcast
Channel: TheUnical Technologies Blog » Browser Compatibility
Viewing all articles
Browse latest Browse all 4

IE8 innerHTML removes attribute quotes

$
0
0

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]
              .replace(/(])/g
              , replacer = function(){
                  var args = Array.prototype.slice.call(arguments);
                  return '="'+(convertToLowerCase ? args[2].toLowerCase() : args[2])+'"'+args[3];
                };
          z[i] = z[i].replace(y[j],y[j].replace(replaceRE,replacer));
          j++;
        }
       }
       zz = zz.replace(zSaved,z[i]);
     }
   }
  zz = zz.replace("colSpan=","colspan=");
  return zz;
 }

Usage :

iereplaceInnerHTML(document.getElementById('test'),'');

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images