Project: Armando Perez - Not Working For Me


#1

The instructions to this project are poorly written and are a chore to read through. I managed to get a general idea of the whole project but I don't understand why my code doesn't work. No matter what I tried nothing would happen in the display window.

Can someone help me out here?

var main = function() {
  $('.nav li').click(function() {
    var category = $(this).attr('class');

    $('.nav li').removeClass('active');
    $(this).addClass('active');

    if(category === $('.nav-consumer')) {
      $('.thumbnail').removeClass('selected');
      $('.consumer').addClass('selected');
    }
    else if(category === $('nav-mobile')) {
      $('.thumbnail').removeClass('selected');
      $('.mobile').addClass('selected');
    }
    else if(category === $('.nav-commerce')) {
      $('.thumbnail').removeClass('selected');
      $('.commerce').addClass('selected');
    }
    else if(category === $('.nav-enterprise')) {
      $('.thumbnail').removeClass('selected');
      $('.enterprise').addClass('selected');
    }
    else if(category === $('.nav-all')) {
      $('.thumbnail').removeClass('selected');
      $('.all').addClass('selected');
    }    
  });
};
 
$(document).ready(main);


#2

Hi Maurice,

$(this).attr('class');

Try looking at the class attribute on those elements in the HTML file, and compare the text inside class="..." to what you're checking if category is equal to in your JS file.


#3

i was working in this project and like Maurice i don't see why . $('.nav-consumer') is not the right value to check if category is equal to.

if(category === $('.nav-consumer')) {
  $('.thumbnail').removeClass('selected');
  $('.consumer').addClass('selected');

please help me? what am i missing.


#4

@hjarte17 Look at the class attribute on the elements. All you want is:

if (category == "category name") {
 // ...
}

"category name" will get replaced with the exact text in the class attribute on the element. You're not selecting an element, just looking at it's class name and comparing category to that string.


#5

I understand my mistake now. Thanks!


#6

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.