How to cancel a dropdown while it’s open

  drop-down-menu, function, javascript

I have a problem with my dropdown menu, I can show it if I click but I can’t hide it the remove function is missing, can you help me please ? I give you the part of the code you need

if (current !== "index.html") {
    $(this).parents('.nav-item').last().find(".nav-link").attr("aria-expanded", "true");
    if ($(this).parents('.sub-menu').length) {

Source: Ask Javascript Questions