lundi 30 mars 2020

How to remove class from body if condition is not met?

I'm working with an if statement to show an alert message depending on certain conditions.

Under the second condition New Article I want a specific css class to be added (show-banner-alert). I am able to get the css added but its now affecting the conditions following it.

I've tried adding a $("body").removeClass and adding a new class with different properties but I am unable to get rid of the first-class successfully.

Here is my code:

$(window).on("load", function(e) {
  $('.preloader').fadeOut('slow');

  if (document.cookie.includes("isDismissed=true")) {
    document.body.classList.add("alert.container");
  } else if ("@pageTitle" === ("New Article") !== "-1") {
    document.body.classList.add("show-banner-alert");
  } else if ("@pageTitle".indexOf("Test") !== "-1") {
    $("body").removeClass("show-banner-alert").addClass("show-alert");
  } else if ("@pageTitle".indexOf("New Home") !== "-1") {
    document.body.classList.add("show-alert");
  } 
});

Aucun commentaire:

Enregistrer un commentaire