For dynamic content when using jquery 1.7 or later use on () :
$("body").on('click','.addCategoryBtn',function() { console.log('add category clicked'); });
For jQuery 1.6.x and below, including 1.4.3, use delegate () :
$("body").delegate('.addCategoryBtn', 'click', function() { console.log('add category clicked'); });
For jQuery 1.4.2 or lower, use bind after adding:
html += '<br><br><form id="addCategory_form" action=""><input type="text" class="inptCategoryName" placeholder="Kategorie Name"> <input type="text" class="inptHtmlColor" placeholder="Hintergrund: #000FFF"> <input type="text" class="inptTextColor" placeholder="Text: #000FFF"><input type="button" value="Go" class="addCategoryBtn"></form></div>'; $(html).appendTo($('body')); $(".addCategoryBtn").bind("click", function() { console.log('add category clicked'); });
In any case, whatever you do, try to avoid live ()
source share