document.write("<a class=" + str + " href='foo'>xss</a>");
The attacker can set str to "foo onclick=alert(1)".
Then you won't need to escape =.
document.write("<a class=" + str + " href='foo'>xss</a>");
The attacker can set str to "foo onclick=alert(1)".