jquery - Dynamically populated UL items not clickable the first time, fine after that -


I have a jQuery function that takes input and uses it to filter a list of links when something Is typed, the function empties an existing U, and then populates it with new light elements, each of which contains links, links are added to the "click" method of jQuery < P> Those resulting links are clickable, but only if The user first clicks anywhere on the page outside the input box, if the user tries to click on a link immediately after the list arrives, the link does not work

Possible signals? If I right-click on the link instead and "inspect the element", it shows the external ul as the active element, clicked not on LI I could go somewhere else And first click and then observe the element, then LI is active element

In addition, if I leave the step which empties ul Instead of just engages in the current list, all links are expected Work in a similar way.

Anyway, the fact is that the new list should be "at the top" immediately after the population is populated, it indicates why the links have not been found. The question is why does why get a focus like this (or at least until some - clicked on a page) in the UL?

.on ( .live ) method Instead of .click it will wire any thing that is automatically added to the DOM:

  // Instead: $ (' Abc '). Click (function () {alert ('hello');}); // Use it: $ ('.abc') ('Click', function () {alerts ('hi');});   



Comments