Why isn't this if/else statement working?

Trying to code this if/else statement and it’s not functioning. The purpose of the statement is for a data-filter to be active when the page loads and when a menu item is selected the correct data-filter items are displayed.

if(document.getElementById("portfolio")){
  var $grid = $(".grid").isotope ({
     if(document.ready){
        filter = ".all"
     } else {
           itemSelector: ".all",
           percentPosition: true,
           masonry: {
           columnWidth: ".all"
        }
     })
  };

If it’s the if-statement itself you’re struggling with then there’s an awful lot of other code there don’t you think?
In the more likely scenario that it’s the condition or one of the operations or even invoking that whole piece of code, then, which particular part misbehaves? You can use your browser’s debugger or console.log to find out more about what is going on. You might ask yourself questions like, “does this code run at all”, “what is the value that my condition evaluates to”, “which branch gets executed”, “is this and that operation having the desired effect”

3 Likes