0

i have a problem when,i add a link with a class="add-item" using append function in page,

this link added to page more than one times,thats mean i want add a list with mentioned link that when click on any of them run one function when i add this link handwork to page isnt problem,but when i add link with jquery append my func isnt running

please check below codes //add link

$temp.append("<li>" + $("input[name=title]").val() + "<a href='#' class= 'add-item' >(Add)</a><ul></ul>");
$(".add-item").click(function(){
some code ...
});
hi lo
  • 67
  • 4
  • Could please give some specific code in codepen or jsfiddle. Then I think I can resolve your issue. Also try to find solution in w3schools. – Aayushi Kambariya Jun 03 '19 at 07:11
  • You have to use `$(document).on("click",".add-item",function() {})` – Carsten Løvbo Andersen Jun 03 '19 at 07:13
  • 1
    Possible duplicate of [$(document).on('click', '#id', function() {}) vs $('#id').on('click', function(){})](https://stackoverflow.com/questions/14879168/document-onclick-id-function-vs-id-onclick-function) – Roy Bogado Jun 03 '19 at 07:14
  • thanks for all, my answer was $(document).on("click",".add-item",function() {}) – hi lo Jun 03 '19 at 07:33

0 Answers0