jQuery / wordpress issue with .addClass based on url
Posted
by Jonathon Joyce
on Stack Overflow
See other posts from Stack Overflow
or by Jonathon Joyce
Published on 2010-04-22T11:53:49Z
Indexed on
2010/04/22
12:43 UTC
Read the original article
Hit count: 561
Hi,
I'm have some issues adding a class to 2 navigation links on a theme.
I need to add a class based on a url string as i'm redirecting the page to another.
You can see the blog here: http://208.43.250.67/~thingsig/
Links are: 'Blog' and 'Keepers'
I'm using the following code:
<script type="text/javascript">
if (window.location.pathname.indexOf('/category/blog/')){
if ( $('#nav ul li a span').text().contains('BLOG') ){
//add class 'current_page_item' to:
$('#nav ul li').addClass('current_page_item');
}
}
if (window.location.pathname.indexOf('/category/keepers/')){
if ( $('#nav ul li a span').text().contains('KEEPERS') ){
//add class 'current_page_item' to:
$('#nav ul li').addClass('current_page_item');
}
}
</script>
Can anyone see why that doesnt work?
I get the following error: $ is not a function [Break on this error] if ( $('#nav ul li a span').text().contains('BLOG') ){
© Stack Overflow or respective owner