adding unique class for new div <p>I want add a unique class for each new div after input, how is it in my code?</p> <p>Add class for this: <code>&lt;div class="thing"&gt;&lt;/div&gt;</code></p> <p><strong>DEMO:</strong> <a href="http://jsfiddle.net/wAwyR/2/" rel="nofollow">http://jsfiddle.net/wAwyR/2/</a> => please in here(field) typing a number for adding new input.</p> <pre><code>function unique() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i &lt; 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } $('input').live("keyup", function () { $('.lee').empty(); var $val = $(this).val(); for (var i = 0; i &lt; $val; i++) { $('.lee').append('&lt;input type="text" name="hi" class=""&gt;div class="thing"&gt;&lt;/div&gt;'); $('input[hi]').next('div').attr('class', unique()) } }); </code></pre>