locked
for loop in javascript only running once.. RRS feed

  • Question

  • User181930479 posted

    i am trying to iterate inside of a treeview control in asp.net , to get the text of an id inside table 3 , its working fine except that im getting only one value .... hope someone can help.... :(

    below is my code:

    <script type="text/javascript">
    
            function ora() {
    
               
           
                var x = document.getElementById('if1').contentWindow.document.getElementById("TreeView1").getElementsByTagName('table')[3].querySelectorAll("tbody tr td a");
    
    
    
                for (var i = 0; i < x.length; i++) {
                   
                    console.log(x[i].innerText);
               
    
                }
    
              
            }
        </script>
    Friday, December 15, 2017 10:18 AM

All replies

  • User1400794712 posted

    Hi NAF,

    According to the code, it seems you are using table in treeview control. Could you please share me the HTML code? Then I can understand this problem better.

    Besides, you said that you were going to access the third table. The index starts from 0. So, the third table should be ('table')[2] :

    var x = document.getElementById('if1').contentWindow.document.getElementById("TreeView1").getElementsByTagName('table')[2].querySelectorAll("tbody tr td a");

    You can also add 'debugger;' above 'for' loop. Then in the browser, use F12 developer tools(Open it with F12, then refresh the page) to check the value of 'x'.

    Best Regards,

    Daisy

    Monday, December 18, 2017 2:49 AM