Roy Harper
Coder
I am creating messaging process but I encounter problem with marking messages as important/unimportant.

What I am trying to achieve is, if I mark those messages as important, I will append that icon to specific element. And if I mark it again as unimportant, the icon will be removed.
However, something weird is happening to adding/removing that icon, which I couldn't figure out how to solve. So, just like the read/unread, I'd like to toggle between important/unimportant.

What I am trying to achieve is, if I mark those messages as important, I will append that icon to specific element. And if I mark it again as unimportant, the icon will be removed.
However, something weird is happening to adding/removing that icon, which I couldn't figure out how to solve. So, just like the read/unread, I'd like to toggle between important/unimportant.
PHP:
<tr class="<?php echo $isRead; ?>" data-id="<?php echo $key['mailID']; ?>">
<td class="check-mail">
<input type="checkbox" class="i-checks mail" autocomplete="off">
</td>
<td class="mail-contact"><a href="mail_detail.php?id=<?php echo $key['mailID']; ?>"><?php echo ucwords(strtolower($guiClass->e($key['name']))); ?></span></a></td>
<td class="mail-subject"><a href="mail_detail.php?id=<?php echo $key['mailID']; ?>"><?php echo mb_strimwidth(ucfirst($guiClass->e($key['subject'])), 0, 60, "..."); ?></a></td>
<td class="text-right mail-date"><?php echo time_passed(date(strtotime($key['created_at']))); ?></td>
</tr>
JavaScript:
$("#mark-as-important").click(function () {
var span = $(
"<span class='float-right important'><i class='fa fa-certificate'></i></span>"
);
$(".mail:checked")
.closest("tr")
.find(".mail-contact")
.find("a")
.each(function () {
if ($(this).find(".important").length) {
$(this).children(".important").remove();
} else {
$(this).append(span);
}
});
});