Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes you can. However, if the first goes wrong, the second won't fire.</p> <p>Use this to catch errors:</p> <pre><code>try { //try executing the functions function1(); function2(); } catch(error) { // If there's an error alert(error); // alert the error. } </code></pre> <p>It is a good practice to put <code>try</code> and <code>catch</code> when experimenting with javascript.</p> <p><strong>Edited: Sorry i confused childNodes[] with childNodes.item().</strong></p> <p>By the way, I tried something like this, and it works just fine:</p> <pre><code>&lt;head&gt; &lt;script&gt; window.onload = function() { div = document.getElementById("someDiv"); length = div.childNodes.length; first(); second(); } function first() { for(var i=0;i&lt;length;i++) { var set = div.childNodes.item(i); set.setAttribute("name", "span " + (i+1)); } } function second() { for(var i=0;i&lt;length;i++) { name = div.childNodes[i].getAttribute("name"); console.log(name); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id='someDiv'&gt;&lt;span id='span1'&gt;&lt;/span&gt;&lt;span id='span2'&gt;&lt;/span&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p><strong>UPDATE: I found the error:</strong> Actually there's nothing wrong with your code. It works just fine, however, the last item of boje is empty space, which means, a text node. That's why the error keeps showing up. Change <code>for(i=1; i&lt;broj; i++)</code> with <code>for(i=1; i&lt;broj-1; i++)</code> and everything should be good.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload