Reputation: 730
I want to open an anchor div on my website when a user surfs to a link without the # in the address bar. For example; when a user goes to www.website.com/nameofdiv it has to auto open the div with the same anchor tag name (www.website.com/#nameofdiv)
I use the following script to open and close anchor div's on my website:
function slideonlyone(thechosenone) {
$('.show').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).fadeIn(500);
}
else {
$(this).fadeOut(500);
}
});
}
This is the HTML click event i am using:
<a href="#nameofdiv" onClick="javascript:slideonlyone('nameofdiv');">link</a>
I tried some stuff with the .htaccess and with the next script but it didnt worked.
window.location.href.replace(/#.*/,'');
I hope I explained it well enough and I hope someone can help me!
Upvotes: 0
Views: 259
Reputation: 281405
If you're calling that code from a click
handler, make sure you return false
from the click handler, or call event.preventDefault()
.
Upvotes: 4