The value of u and v are coming correctly as 1 and 0... but the values are not being used in the statement "t[i].children[v].onclick=function(){}" ..!!
This works perfectly when I used 1 in the place of u and 0 in the place of v!!!
Here is the code :
    <div class="dropdown">
    <span class="menu-toggler">Menu</span>
    <ul class="dropdown-menu">
    <li>First Part</li>
    <li>Second Part</li>
    </ul>
</div>
<script type="text/javascript">
function init()
{
    t = document.getElementsByClassName("dropdown");
    for(i=0;i<t.length;i++)
    {
        v = getMenuToggler(t[i]); // v is becoming 0 correctly
        u = getDropDown(t[i]); // u is becoming 1 correctly
 // the next statement is not working properly!!!
        t[i].children[v].onclick=function(){if(this.parentNode.children[u].classList.contains("menu-
open")){this.parentNode.children[u].classList.remove("menu-open");}else{this.parentNode.children
[u].classList.add("menu-open");}}
    }
}
function getDropDown(x) // this function is all right... u can ignore this
{
    for(i=0;i<x.childElementCount;i++)
    {
        if(x.children[i].classList.contains("dropdown-menu"))
        return i;
    }
    return -1;
}
function getMenuToggler(y) //this function is all right... u can ignore this
{
    for(i=0;i<y.childElementCount;i++)
    {
        if(y.children[i].classList.contains("menu-toggler"))
        return i;
    }
    return -1;
}
</script>
<script>window.onload=init;</script>
thank you in advance... :)
 
     
     
     
    
tag?
– goelakash Apr 12 '15 at 20:21– Samarpan Das Apr 12 '15 at 20:24