Skip to content
Advertisement

why, by clicking on the span, its text is not thrown into the input? javascript, jquery

why, by clicking on the span, its text is not thrown into the input?

html

JavaScript

error in devtools:

JavaScript

what is wrong with addEventListener?

Advertisement

Answer

There are several problems with the approach.

  1. You have a loop with multiple i values and only use value of the last one after loop completes
  2. Trying to use querySelector() before the html string is inserted in document
  3. Using # in the element id="#service

A better approach would be to use a common class name and event delegation instead.

JavaScript

Then outside of the $('#ajax-service').keyup.. do:

JavaScript

Understanding Event Delegation

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement