0

My block of jquery code is working on the existing field for address, but if user adds a new field for extra address, jquery code is no longer working even the selector I used is for class.

this is my block of code.

$(document).ready(function () {
   const searchInput = document.querySelector('.autocomplete');    
   loadGooglePlaces(searchInput, {
      types: ['geocode'],
  });
});

I need to make sure that this block of code will be applied to another address field that the user added.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
jhune
  • 3
  • 2
  • Does this answer your question? [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – bassxzero Nov 18 '21 at 09:02
  • It's hard to tell from the small amount of code exactly what's *"no longer working"*. Normally this would be fixed by event delegation (see link in comment above) - but that won't help if the issue is in `loadGooglePlaces`. Please be specific. You can probably fix this by re-calling `loadGooglePlaces(newInput` when you add your new input; if you include that code, we might be able to help. – freedomn-m Nov 18 '21 at 09:09

0 Answers0