Custom Href links in R shiny

My question involves R and a custom javascript function. I am asking because I am familiar with R but not as familiar with javascript.

Context: My app has a landing page and pages for each state in the sidebarMenu drop downs. There is a leaflet map on the landing page for all the states. The pop up on the state map has a hyperlink that takes a user directly to the state's page when clicked. This saves the user time by just linking directly to the state page from the map itself instead of having to navigate to the state page from the side bar menu. But the user can also navigate to the state pages on the side bar menu drop downs if they want another option to do so.

Problem: However, the problem is that the javascript function (below) I am using to create that direct link to the state pages only works for states that are a single word (ie "Alabama", "Alaska", "Delaware", "Colorado", etc). The functionality does NOT work for states that are two words such as "New Mexico", "New Jersey", "Rhode Island", "North Dakota", "South Dakota", etc.

For reproducibility here is the function I am using. I got it from this link: https://groups.google.com/g/shiny-discuss/c/fZORQAqkKsQ

// script for custom href
var customHref = function(tabName) {
var dropdownList = document.getElementsByTagName("a");
for (var i = 0; i < dropdownList.length; i++) {
var link = dropdownList[i];
if(link.getAttribute("data-value") == tabName) {
link.click();
}
}
window.scrollTo( 0, 0 );
};

The function is calling the states based on "tabName". So for instance, South Dakota's tab name in the UI is "SouthDakota" but the name of the state that the javascript function and in the actual data is referred to as "South Dakota" with a space. I have tried to escape the space in the javascript function call with various quotes and backticks but that does not work. I have tried to add a space to the tabName in the UI but that does not work either. I think the solution is more complex and so I am seeking help from those who are more familiar with custom java functions.

How can I escape spaces in a javascript function above that is used for a customHref?