I need some help in jQuery. When the page is loaded, I have a tag:
So I can select it in my script by: $('#root-directory')
Then, I select it and add some contents within when it is clicked by using the .html() jQuery function.
These contents contains new elements with a class name (example: "has-child") that is never used before in the page.
After that, I create a function which must manipulate the class has-child.
And the issue appear on this function, it finds any elements with this class even if the elements can be inspected in the DOM. In the same way, if I create a trigger using this class name, it will return an error.
So, the solution I'm searching for is how manipulate the "has-child" elements in my script.
<ul id="root-directory"></ul>
let root = $('#root-directory');
$(root).on('click', function(){
let html="";
for(let i = 0; i < 4; i++) {
if(i % 2 === 0) {
html += `<li>item number ${i}</li>`
}
else html += `<li clas="has-child">item number ${i} with child</li>`
}
})
$('li.has-cild').click(function(){
//...Add some new contents
})
//And this return a reference error because the selection is said undefined.
`? (Which I don’t see in your code)