accessing DOM elements, when button on click to get (name[i].firstChild.nodeValue;),
<p>I'm trying to alert just the first nodeValue not all of them, when a button is clicked. Buttons and tables are created dynamically from SQL.</p>

<pre><code>function dodb() {
    var name = document.getElementsByName('prezime');
    var elements = document.getElementsByName('bt');

    for (var i = 0; i &lt;= elements.length; i++) { 

        if (elements[i].type == 'button') {

            var name1 = name[i].firstChild.nodeValue;
            alert ("The " + elements[i].value + " button is click");
            alert(name1);

        }

    }       
}
</code></pre>

<p>I solved the problem:</p>

<pre><code>for (var i = 0; i &lt;= elements.length; i++) { 

    // if (elements[i].type == 'button') {

        var oelements = elements[i];
        oelements.onclick = (function(value) {
            var name1 = name[i].firstChild.nodeValue;
            return function() {
                alert(value);
                // alert ("The " + elements[i].value + " button is click");
                alert(name1);
            }
        })(i);
    }
}       
</code></pre>
