$(document).ready(function(){
var page = window.location.hash;
if(page != ""){
$('a[href='+ page +']').addclass('selected');
pageload(page.replace('#/page/', 'pages/?load='));
}
$('#top a').click(function(event){
$('#top a').removeClass('selected');
$(this).addClass('selected');
pageload($(this).attr('href').replace('#/page/', 'pages/?load='));
event.preventDefault;
});
});
<div id="top">
<a href="#/page/link">Link</a>
<a href="#/page/link">Link</a>
<a href="#/page/link">Link</a>
<a href="#/page/link">Link</a>
<a href="#/page/link">Link</a>
</div>
So when i'm trying to do this, and load up a page using the window.location.hash
, i get an error in the console saying:
Uncaught Error: Syntax error, unrecognized expression: [href=#/page/link]
How can i make this work?
Try this instead:
$('a[href="'+ page +'"]').addClass('selected');
(You need to escape the value of the href
– with this, you get a[href="#/page/link"]
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With