I have a list being dynamically generated and then I click on the item and pass the index()
to another function.
The problem is that this list is being populated dynamically and my code does not respond when I do click
event. BUT, if I add a couple of Static li elements to the list in addition to the dynamically populated ones those Static ones work. Its very odd.
Some code:
This dynamically creates the list:
function SetOpenRecentURL( openRecentURL ) {
$('#recentProjectsId').append('<li>' + openRecentURL + '</li>')
}
This is the click event to pass the Index():
$('#recentProjectsId li').on('click', function () {
var projIndex = $(this).index();
console.log(projIndex)
OpenProject()
})
The HTML with a few Static Li's
<div class="recentProjects" id="recentProjectsId">
<li>Test 1</li>
<li>Test 2</li>
</div>
When I run my program my list looks perfect and includes my static li plus my dynamic ones, but I cannot click on the dynamic ones, only static.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…