IE throws exception "Access denied" on document.selection.createRange()

IE throws exception "Access denied" on hidden elements and sometimes if selection.type is "None"