There is a div
element:
<div id="ddDistr" class="searchBoxSortDistrict" tabindex="1">
<ul id="ddd">
</ul>
</div>
I have inserted HTML from json
into it:
$("#ddd").html(" "), $.each(dis, function(
index, value) {
$("#ddd").append( "<li><a style=\"cursor: pointer;\">"
+ value.fieldName + "("
+ value.count + ")</a></li>");
}
);
I am trying to change the class of onclick <li>
to .active
.
$('#ddDistr li > a').click(function() {
console.log('dd');
$(this).siblings('li').removeClass('active');
$(this).addClass('active');
});
However, this code is not working. Can you help me identify the issue?
Furthermore, I want to retrieve value.fieldName
from the active <li>
element and send it via POST
.
How can I achieve this? Any suggestions?