0

I am trying to remove a particular class from all external urls on a page, only if a cookie has been set. I have the below code but doesn't work as expected.

jQuery(document).ready(function() {
  var vLink = jQuery('.external a');
    if (localStorage.getItem("cookiename")) {
        vLink.removeClass('myclass');
    }
});
Barmar
  • 741,623
  • 53
  • 500
  • 612
JoaMika
  • 1,727
  • 6
  • 32
  • 61
  • 3
    Are you looking for a *cookie* or for an item in *local storage*? They are two different things. – David May 25 '22 at 16:04
  • I am looking for the name of a particular cookie using only jquery – JoaMika May 25 '22 at 16:15
  • I couldn't find an answer purely with a jquery method using no plugins.. – JoaMika May 25 '22 at 16:16
  • 1
    Then the problem is that your code isn't looking for a cookie, it's looking in local storage. Refer to the linked duplicate for information on reading a cookie in JavaScript. (Which, incidentally, is unrelated to jQuery.) – David May 25 '22 at 16:16
  • ok thank you but can this be done with jQuery without using JavaScript ? – JoaMika May 25 '22 at 16:18
  • 2
    No, jQuery itself can not be used without JavaScript. – David May 25 '22 at 16:20

0 Answers0