Why my jquery code wont work if with ID but Class <p>I have html code like this.</p> <pre><code>&lt;input onkeyup="ave()" type="text" name="1" class = "ave" style="width: 60px"&gt;&lt;/td&gt; &lt;input onkeyup="ave()" type="text" name="2" class = "ave" style="width: 60px"&gt;&lt;/td&gt; &lt;input onkeyup="ave()" type="text" name="3" class = "ave" style="width: 60px"&gt;&lt;/td&gt; </code></pre> <p>The jQuery like this</p> <pre><code>function ave(){ $('.ave').keyup(function(){ var sum = 0; var ave = 0; $('.ave').each(function(){ sum += +$(this).val(); }); var ave = sum/3; $('.total').val(ave.toFixed(2)); }); } </code></pre> <p>If I change 'class' to 'ID' and <code>$('.ave')</code> to <code>$('#ave')</code> the code won't work!</p>