Code with classList does not work in IE?
The classList
property is not supported by IE9 and lower. IE10+ supports it though.
Use className += " .."
instead. Note: Do not omit the space: class names should be added in a white-space separated list.
var img = new Image();
img.src = '/image/file.png';
img.title = 'this is a title';
img.className += " profilePic"; // Add profilePic class to the image
var div = document.createElement("div");
div.className += " picWindow"; // Add picWindow class to the div
div.appendChild(img);
content.appendChild(div);
As mentioned by othes, classList
is not supported by IE9 and older. As well as Alex's alternative above, there are a couple of polyfills which aim to be a drop-in replacement, i.e. just include these in your page and IE should just work (famous last words!).
https://github.com/eligrey/classList.js/blob/master/classList.js
https://gist.github.com/devongovett/1381839