0

I am blanking on how to get this to work. Basically I am just trying to go over a list of items that are nav links and compare them to the title of the page. If the title is the same as the list item, change the color. Basically highlight what page you are on. Only this highlights all the items.

var secondNav = $('.custom-post-side-list ul li a');
var title = $('.custom-post-main h1');

secondNav.each(function(index, el) {
    var $this = $(this);

    if(title = $this) {
        $this.css('color', 'red');
    }
});
Packy
  • 3,405
  • 9
  • 50
  • 87

1 Answers1

0

So basically I wasnt comparing two of the same objects. So what I did was grab the text from the two elements and compared that. If true, then change the element.

//Highlight current 
var secondNav = $('.custom-post-side-list ul li a');
var title = $('.custom-post-main h1');

secondNav.each(function(index, el) {
    var $this = $(this);
    var titleText = title.text();
    var navText = $this.text();

    if (navText == titleText) { 
        $this.css('color', 'red');
    }
});
Packy
  • 3,405
  • 9
  • 50
  • 87
  • Oh I see, yeah his answer won't work and neither will my edit. Your comparing the text. Glad you found a solution –  Nov 06 '15 at 17:47