title: Can I assign an attribute (or some sort of equivalent) to a Javascript variable? Sample code included
body: <p>(Preface: my code is running JQuery)</p>
  
  <p>I have the following code, which reduces a fraction and then displays the result:</p>
  
  <p>This is the function that simplifies the fraction:</p>
  
  <pre><code>function reduce(numerator,denominator){
    var gcd = function gcd(a,b){
      return b ? gcd(b, a%b) : a;
    };
    gcd = gcd(numerator,denominator);
    if ((denominator/gcd) == 1) {
    return [numerator/gcd];
    } else {return [numerator/gcd +"|"+ denominator/gcd];
    }
  }
  </code></pre>
  
  <p>This displays the result - in this case <code>1|3</code> - when a span in the HTML body has the class <code>reducedfraction</code>:</p>
  
  <pre><code>var reducedfraction = reduce(4,12);
  $('.reducedfraction').html(reducedfraction );
  </code></pre>
  
  <p>All of the above works just fine.<br>
  <strong>Here's the modification I'm trying to make:</strong></p>
  
  <p>If the fraction cannot be reduced (in other words gcd == 1), a parent span with the class <code>SimplificationPrompt</code> would disappear. </p>
  
  <p>I don't believe you can add an attribute to a variable, but I tried in vain anyway because I didn't know what else to do. Here's what I tried:</p>
  
  <pre><code>function reduce(numerator,denominator){
    var gcd = function gcd(a,b){
      return b ? gcd(b, a%b) : a;
    };
    gcd = gcd(numerator,denominator);
    if ((denominator/gcd) == 1) {
    return [numerator/gcd];
    } else {
  return [numerator/gcd +"|"+ denominator/gcd];
  if ((gcd == 1)){
       $(this).attr({  // THE IDEA HERE IS THAT A GCD OF 1 WOULD FLAG THIS IN SOME WAY (I JUST RANDOMLY CHOSE TITLE)
                  "title" : "HideSimplificationPrompt"
              });
      }
        }
      }
  
  $(document).ready(function () { //AND THEN THIS FUNCTION WOULD HIDE THE SPECIFIED PARENT SPAN 
  $("[title=HideSimplificationPrompt]").parent(".SimplificationPrompt).hide();
  });
  </code></pre>
  
  <p>Newbie here, trying to learn through experimentation like this. Any help would be much appreciated. Thanks!</p>