Yes, the "<" sign in the for loop is the culprit. As Doitsu explain using CDATA is a solution. As is including the script from a separate javascript resource.
You can wrap javascript // comment indicators around the CDATA piece as well for some browsers and e-readers ala:
And I agree with Doitsu using a class selector would be better than duplicating id attributes.