Search in Ajax within div clone jquery

1

I have a search in an input that returns the result in ajax, type autocomplete that is working (when I type 3 first digits it shows the results), but when I put this input inside a div "clone" (jquery) it does not search and returns no results ...

I put the code in jsfiddle: link

    
asked by anonymous 09.12.2016 / 15:03

2 answers

2

The problem is that when you use $("#produto").keyup(function(){ the event handset is only listening for events in the #produto element that already existed when the page was loaded. In this case, and as Lucas also mentioned , you can not use ID because on the page there can only be one element with each ID.

If you use this delegate event , and joining both #engloba-template and #conteudo_engloba could look like this: / p>

$('#engloba-template, #conteudo_engloba').on('keyup', 'input[name="produto[]"]', function() {

jsFiddle: link

    
09.12.2016 / 15:55
1

When you clone it is understandable to repeat id in your case. Try to make the selection for any property:

HTML

<input type="text" autocomplete="off" id="produto" produto name="produto[]">
                                                   ^^^^^^^

JS

$("input[produto]").keyup(function(){ });
    
09.12.2016 / 15:13