Create element among child elements of the same parent

1

According to the code below:

var ul = document.getElementsByTagName('ul');
var ref = ul.item(0).children;
var saida = '';

  for (i = 0; i <= ref.length; i++) {
if (i == 0) {
	var HTMLString = "<div style='background-color: blue; width: 60px; height: 60px;'>";
    var div = document.createElement('div');
    div.innerHTML = HTMLString;
    ref[i].parentElement.insertBefore(div.firstChild, ref[i]);
}
if (i == 11) {
	var HTMLString = "</div><div style='background-color: red; width: 60px; height: 60px;'>";
    var div = document.createElement('div');
    div.innerHTML = HTMLString;
    ref[i].parentElement.insertBefore(div.firstChild, ref[i]);
}
  }
<!DOCTYPE html>
<html>
<body>

<div id="div1">
  <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
  <li>13</li>
  <li>14</li>
  <li>15</li>
  <li>16</li>
  <li>17</li>
  <li>18</li>
  <li>19</li>
  <li>20</li>
  <li>21</li>
  <li>22</li>
  <li>23</li>
  <li>24</li>
  <li>25</li>
  </ul>
</div>

</body>
</html>

It would be possible to open <div> before the first element <li> and close it after the 10th element <li> ??

If yes, how?

Note: According to the <script> that I created it creates the element <div> and closes in the same place ...
I used the concept of answer of this question .

    
asked by anonymous 14.09.2017 / 22:29

0 answers