how to make submenu to open on the left side?

how to make submenu to open on the left side?

Hi,
Please, can someone helps me.
I have to change opening a submenu on left side, instead on right side when it floated right.

I've used this function, but it doesn't work:
$('body, html').css('overflow', 'hidden');
  var screenWidth = $(window).width();
  $('body, html').css('overflow', 'visible');
   
  if (screenWidth > 767)
  {   
    $(".dropdown-menu").hover(function () {
        var menuPos   = $(this).offset().left + $(this).width() + $(this).find('ul').width();
        var newPos    = $(this).offset().left - $(this).find('ul').width();
        var windowPos = $(window).width();
        var oldPos    = $(this).offset().left + $(this).width();
       
        if (menuPos > windowPos)
        {
            $(this).find('ul').offset({ "left": newPos });
        }else{
            $(this).find('ul').offset({ "left": oldPos });
        }
       
    });
  }

Thanks in advance.

Tegatti