I am facing an issue with removing HTML divs generated using jinja2 as shown below:
{% for student in students %}
<div class="item" id="{{ student.id }}_div">
<div class="right floated content">
<div class="negative ui button compact remove_from_class" id="{{ student.id }}">Remove from Class</div>
</div>
<i class="large user icon middle aligned icon"></i>
<div class="content">
<div class="header">
<h3><u>{{ student.get_full_name }}</u></h3>
</div>
<div class="description">{{ student.email }}</div>
</div>
</div>
{% endfor %}
Despite having a script to remove the parent div upon clicking, I'm encountering a problem where the div is not being removed. The code snippet of the removal process is provided below:
$(".remove_from_class").each(function () {
$(this).on("click", function () {
var id = this.id;
var url = window.location.pathname.split('/');
var set_id = url.pop() || url.pop()
$.ajax({
method: 'POST',
url: '/ajax/delete_from_class/',
data: {
'id': id,
'set_id': set_id,
},
dataType: 'json',
success: function (data) {
if (data.success == true) {
var div_id = id + "_div";
var parent_div = $(div_id);
parent_div.remove();
} else {
alert("Student wasn't removed!");
}
}
})
})
})
Any insights or suggestions on why the div is not getting removed would be greatly appreciated! Thank you.