0

I am constructing Jquery elements dynamically and i have used .clone() and .html() and .append() alot in my code. this works fine with chrome and firefox even IE9. But IE8 Its creating element with attribute sizeset and sizechar. My Jquery version is 1.7. I know there alot around 4 to 5 Issue raised in Stackoverflow on same topic, but i havent found even one answer useful . Please help me with this as it's blocking my complete work. i cant user removeAttr as , its sizcache08213372050765756 some random junk value. and if i use regEx

var re = /\s*(sizset|sizcache)\d*="[^"]*"/gi;
source = source.replace(re,'');

mentioned in one of the thread

How to get rid of sizset and sizcache attributes from jQuery?

then return value is "no", i dono how.

IE8 Contruction

<DIV class=findings sizcache08213372050765756="38" sizset="54">
   <DIV id=fnd-cv1 class="finding finding-readonly fnds-O closed" sizcache08213372050765756="38" sizset="54">
      <DIV class="cap-fnd-summary finding-summary summary clearfix" sizcache08213372050765756="36" sizset="0">
         <SPAN class=line-item>MS-2.3</SPAN>
         <A class=finding-title href="" jQuery17034048751834028246="188" toggleview="closed" sizcache08213372050765756="36" sizset="1"><SPAN class=icon-text-toggle></SPAN>Fnd 10</A><SPAN class="status finding-status">Open</SPAN> <SPAN class="status finding-status-item PA" href="">PA</SPAN> <SPAN class="status finding-status-item CA" href="">CA</SPAN> <SPAN class="status finding-status-item ROOT" href="">ROOT</SPAN> 
      </DIV>
      <DIV class="finding-items clearfix" sizcache08213372050765756="38" sizset="54"><SPAN class=recidivism sizcache08213372050765756="36" sizset="9"></DIV>
   </DIV>
   </SPAN>
</DIV>
Community
  • 1
  • 1
SJ-B
  • 97
  • 1
  • 11
  • 1
    Show how you're using that in your code. Since it should work if you use it correctly, you must be using it wrong, but we can't help you if you don't show more context. – Barmar Jan 13 '14 at 07:08

1 Answers1

1

Don't use regex to parse HTML, iterate over elements and attributes, and remove them if they match a condition.

I whipped together a jQuery plugin that should work

$.fn.sizRemove = function() {
    return this.each(function() {
        for (var i=this.attributes.length; i--;) {
            var n = this.attributes[i].nodeName;
            if (n.indexOf('sizset') === 0 || n.indexOf('sizcache') === 0)
                this.removeAttribute(n);
        }
    });
};

to be called like

$('#fnd-cv1').sizRemove();
// or for all elements
$('*').sizRemove();

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388