Dynamically add ID to header based on header nam

<script>
  jQuery(document).ready(function($) {

    jQuery('h1, h2, h3, h4, h5, h6').each(function(index) {
      var headingText = $(this).text().trim();
      let headingId = headingText.normalize('NFD').replace(/đ/g, 'd').replace(/Đ/g, 'D').replace(/([\u0300-\u036f]|[^0-9a-zA-Z\s])/g, '').replace(/[^\w\-]+/g, '-').toLowerCase();
      $(this).attr('id', headingId);
    });
    
    if (window.location.hash) {
        var targetElement = $(window.location.hash);
        if (targetElement.length) {
            $('html, body').animate({
                scrollTop: targetElement.offset().top
            }, 1000);
        }
    }
  });
</script>