I am creating a dynamically generated html <ul>
in jquery which has some <li>
elements in it. I want an active
class be added to any of the <li>
elements by hovering. I've tried some functions in jquery but it won't change <li>
elements, it will only work if I try it on <ul>
element.
Here is my html code:
<div class="col-md-3 all_session_section" id="listRight">
<ul class="meeting_lists" id="meeting_lists"></ul>
My Javascript code:
$.ajax({
url: myURL,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if (data.d.results.length > 0) {
AllTask = data.d.results;
html = '';
for (var i = 0; i < Number(AllTask.length); i++) {
html += '<li class="pass" data-tab="tab-1">';
html += '<div class="clear_border_active"></div>';
html += '<a href="#">';
html += '<div class="title">' + AllTask[i].Title + '</div>';
html += '<div class="details d-flex justify-content-end align-items-center"><span class="salon mr-3">' + AllTask[i].meeting_place + '</span><span class="date">' + JDate + '</span></div></a></li>';
}
document.getElementsByClassName('meeting_lists')[0].innerHTML = html;
and my jquery function:
$(".all_session_section ul > li").hover(
function () {
$(this).addClass("active");
},
function () {
$(this).removeClass("active");
}
);
if anyone can help me with this, I would really appreciate that.