title: jQuery set value of an element from an object
body: <p>How can I set a value of an element with JQuery from an object $this?</p>
  
  <p>I have some divs of class "A"</p>
  
  <pre><code>&lt;div class="A"&gt;
    &lt;span name='B'&gt;some text&lt;/span&gt;
    &lt;div&gt;
        &lt;input name='value_1' value='15'/&gt;
        &lt;input name='value_2' value='9'/&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="A"&gt;
    &lt;span name='B'&gt;some other text&lt;/span&gt;
    &lt;div&gt;
        &lt;input name='value_1' value='7'/&gt;
        &lt;input name='value_2' value='12'/&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  ...more divs like those
  </code></pre>
  
  <p>I'm trying to set the text of the spans of name B with the greater value of their inputs (inputs 'value_1' and 'value_2'). </p>
  
  <p>But what I'm trying seems to fail, this is the js (using jquery):</p>
  
  <pre><code>function setSpans(){
      var value1=0;
      var value2=0;
      var setting_value = 0;
      $('.A').each(function(){
          value1 = $(this).find("input[name='value_1']").val();
          value2 = $(this).find("input[name='value_2']").val();
  
          if(value1 &gt; value2)
              setting_value = value1;
          else
              setting_value = value2;
  
          //here comes what I can't accomplish
          $(this).find("span[name='B']").text(setting_value);
  
      });
  }
  </code></pre>