Search code examples
javascriptcssinternet-explorer-11

Strict mode error only in IE11. Can I take off strict mode just for this browser?


I get the error `Assignment to read-only properties is not allowed in strict mode' on this line of my code:

wrapper.style = 'transition: transform 3s;';

This is a chunk of the function it's in:

'use strict';
function work() {
  var wrapper = document.getElementById( 'wrp' ),
  infoPage = document.getElementById( 'i-pg' ),
  body = document.getElementById( 'body' ),

  carA = document.getElementById( 'car-a' ),
  keyA = document.getElementById( 'key-a' ),
  manualA = document.getElementById( 'manual-a' ),
  wheelA = document.getElementById( 'wheel-a' );

  if( this.id === 'info' ) {
    wrapper.style = 'transition: transform 3s;'; //PROBLEM LINE
    wrapper.classList.add( 'up' );
    body.classList.add( 'dark' );
    infoPage.classList.remove( 'down' );
  }
}

This code works perfectly in all modern browsers i've tested. Only in IE11 is this breaking the entire site, stopping all subsequent lines from running.

If I take out the first line: 'use strict'; everything works fine. Is there a simple fix while keeping strict mode on? Or just target IE11 and somehow remove strict mode for that browser?

There might be a better approach.


Solution

  • Why not fix it, instead of ignoring the error?

    wrapper.style.transition = 'transform 3s;';