title: Sass 'if' statement based on existing class
body: <p>I'm new to Sass and would like to use the 'if' statement to detect an existing class on an element in order to generate the relevant css.</p>
  
  <p>My setup has a large number of Javascript generated images, which are assigned a unique ID, as well as a class of "picture" and a randomly assigned class of either top, right, bottom or left.</p>
  
  <p>I am also using a random function for Sass (found here: <a href="https://gist.github.com/chriseppstein/1561650" rel="noreferrer">https://gist.github.com/chriseppstein/1561650</a>), and would like a different value assigned to each ID, so that each element is randomly positioned. </p>
  
  <p>My SCSS has the following, which positions the images based on which class it was assigned:</p>
  
  <pre><code>@for $i from 0 through $number-of-pictures {
    #picture-#{$i}{
  
      &amp;.top {
        left: random($stage-width);
      }
  
      &amp;.right {
        top: random($stage-height);
      }
  
      &amp;.bottom {
        left: random($stage-width);
      }
  
      &amp;.left {
        top: random($stage-height);
      }
    }
  }
  </code></pre>
  
  <p>This works well, but creates a ton of unused declaration blocks. For example, #picture-38 was assigned the class ".top", so all I need is the first declaration block, but the CSS exports all the options:</p>
  
  <pre><code>#picture-38.top {
        left: 38px; //This is a random number that is different for each ID.
  }
  #picture-38.right {
        top: 28px;
  }
  #picture-38.bottom {
        left: 12px;
  }
  #picture-38.left {
        top: 47px;
  }
  </code></pre>
  
  <p>What I need is an if statement, that detects if the element has a class before parsing the css. Something like:</p>
  
  <pre><code>@if "#picture-#{$i} has class $class-top" {
      &amp;.top {
          left: random($stage-width);
      }
  }
  </code></pre>
  
  <p>Any ideas?</p>