 <p>The problem seems to be because of improperly formatted code. The quotes are a little mixed up.</p> <pre><code>$("&lt;div class='child' id='cross" + counter + "'&gt;&lt;/div&gt;") </code></pre> <p>This should work. To insert it into the DOM, you could do something like:</p> <pre><code>$('body').append("&lt;div class='child' id='cross" + counter + "'&gt;&lt;/div&gt;") </code></pre> <p><a href="http://jsfiddle.net/1ok6b2ro/" rel="nofollow">Here's an example</a>.</p>