jQuery change action from another change action
<p>I have the next code:</p>

<p>js:</p>

<pre><code>    $('[id^="check-"]').change(function(){
        var new_id = this.id.replace(/check/, 'new'),
            real_id = this.id.replace(/check/, 'real');
        if ($(this).is(':checked')) {
            $('#'+real_id).val($('#'+new_id).text());
        } else {
            $('#'+real_id).val(0);
        }
    });
</code></pre>

<p>html:</p>

<pre><code>&lt;tr&gt;
  &lt;td&gt;&lt;span id="new-1"&gt;2&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="real-1" id="real-1" value="0"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="checkbox" class="card" id="check-1"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;span id="new-2"&gt;7&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="real-2" id="real-2" value="0"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="checkbox" class="card" id="check-2"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&lt;span id="new-3"&gt;4&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="real-3" id="real-3" value="0"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="checkbox" class="card" id="check-3"&gt;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>The main idea: take the text from <code>new-*</code> and put it into <code>real-*</code> inbox when you click on related <code>check-*</code> checkbox.</p>

<p>Now I want to add another checkbox that mass executes this operation for all the elements.
I tried it:</p>

<pre><code>    $('#main-checkbox').change(function(){
        if ($(this).is(':checked')) {
            $('.card').attr('checked', true);
        } else {
            $('.card').attr('checked', false);
        }

    });
</code></pre>

<p>But it does not work. Why?
How can I start the <code>change</code> action for all those checkouts.</p>

<p>Thanks.</p>
