This is my code:
$('.add').click(function(){ $('#test').append("<div class='tab selected'>TEST</div>"); }); $('.tab').click(function(){ $('.tab').removeClass('selected').addClass('unselected'); $(this).removeClass('unselected').addClass('selected'); }); <input type='button' value='add' class='add' /> <div id='test'> <div class='tab unselected'>TEST</div> </div> This is my issue:
When I click the .tab div that was already defined in html, the function works fine. But, if I add another .tab div using the .add input, the function does not work.
What exactly am I doing wrong here?