I am looking to automatically open a specific anchor div on my website when a user navigates to a link without the # in the address bar. For instance, if a user visits www.website.com/nameofdiv, I want the corresponding div with the anchor tag name (www.website.com/#nameofdiv) to open automatically.
Currently, I have implemented the following script to handle opening and closing anchor divs on my website:
function slideonlyone(thechosenone) {
$('.show').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).fadeIn(500);
}
else {
$(this).fadeOut(500);
}
});
}
Here is the HTML click event that triggers this functionality:
<a href="#nameofdiv" onClick="javascript:slideonlyone('nameofdiv');">link</a>
I have attempted some modifications using .htaccess and the following script, but so far, it has not been successful:
window.location.href.replace(/#.*/,'');
I hope my explanation was clear and I would greatly appreciate any assistance or guidance on this matter!