<p>The Craft.MatrixInput class that manages each Matrix field doesn’t actually get assigned to a variable, so there’s no way to reference it right now. We probably won’t change that, since there wouldn’t be much point to it in the first place. The class doesn’t provide any sort of object-oriented API for managing the blocks; there’s no need for it in the current implementation.</p>

<p>If you want to get a reference to all the blocks’ containers, you can just use a jQuery selector:</p>

<pre class="lang-js prettyprint-override"><code>var $blocks = $('#fields-myMatrixField &gt; .blocks &gt; div');

$blocks.each(function() {
    var $block = $(this),
        id = $block.data('id');
    // ...
});
</code></pre>

CC BY-SA 3.0
2014-10-18T15:18:08.850Z
Great. My reason for asking was just to have something that won't break if you change the markup a lot, but I guess it isn't likely you will do that too often.
Fred Carlsen
CC BY-SA 3.0
2014-10-18T09:55:32.680Z
2014-10-18T09:55:32.680Z
Brandon Kelly
<p>Is there a way to use Craft javascript API to fetch all Matrix rows of a specific field on the entry edit page?</p>

<p>If not, could that be added? Would be useful, for example in terms of fetching the handle/id and using that in the frontend to simulate Matrix inside Matrix.</p>

<matrix><javascript>
Fetching Matrix rows with Javascript
# Fetching Matrix rows with Javascript

(Asked by: username_0 on 2014-10-18)

Is there a way to use Craft javascript API to fetch all Matrix rows of a specific field on the entry edit page?

If not, could that be added? Would be useful, for example in terms of fetching the handle/id and using that in the frontend to simulate Matrix inside Matrix.

**Tags:** matrix, javascript

---

## 1 answers

### Answer by username_1 on 2014-10-18. Score: 1 | Accepted answer

The Craft.MatrixInput class that manages each Matrix field doesn’t actually get assigned to a variable, so there’s no way to reference it right now. We probably won’t change that, since there wouldn’t be much point to it in the first place. The class doesn’t provide any sort of object-oriented API for managing the blocks; there’s no need for it in the current implementation.
If you want to get a reference to all the blocks’ containers, you can just use a jQuery selector:
var $blocks = $('#fields-myMatrixField > .blocks > div');

$blocks.each(function() {
    var $block = $(this),
        id = $block.data('id');
    // ...
});

> **Comments:**
> **username_0**: Great. My reason for asking was just to have something that won't break if you change the markup a lot, but I guess it isn't likely you will do that too often.  

---

