JavaScript in Bootstrap 5

I’m quiet new to building webpages and just started building one with Bootstrap 5.
I want to add/remove the bootstrap class “bg-opacity” to my navbar based on viewport width and thought I can do so with JS. But the function I found is not working, cause BS doesn’t use JQuery anymore. Is there an easy way to add/remove classes that exist in Bootstrap 5?

I would be very happy about an answer.

Cheers and thanks in advance 🙂

I tried to use this function


jQuery(document).ready(function($) {
    var alterClass = function() {
      var ww = document.body.clientWidth;
      if (ww < 767) {
        $('.navbar').addClass('bg-opacity-75');
      } else if (ww >= 768) {
        $('.navbar').removeClass('bg-opacity-75');
      };
    };
    $(window).resize(function(){
      alterClass();
    });
    //Fire it when the page first loads:
    alterClass();
  });