Task: Your challenge is to display a list of span elements in both vertical and horizontal layouts without altering the HTML structure.
Input: an unknown number of span elements within a parent span like the example below:
<span id="parent">
<span id="child-1">1</span>
<span id="child-2">2</span>
<span id="child-3">3</span>
<span id="child-4">4</span>
<span id="child-5">5</span>
<span id="child-6">6</span>
<span id="child-7">7</span>
<span id="child-8">8</span>
<span id="child-9">9</span>
<span id="child-10">10</span>
...
...
...
</span>
Output: Using CSS classes and JavaScript/jQuery, arrange the child-spans in N rows and M columns as specified. The number of rows (N) and columns (M) will vary, so adding additional HTML elements within the parent span is not allowed.
For example, if you have 12 child-spans and N=4 and M=3:
Horizontal order:
1 2 3
4 5 6
7 8 9
10 11 12
Vertical order:
1 5 9
2 6 10
3 7 11
4 8 12
Good luck with the challenge!