https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons
On the page I linked above, there's a sidebar on the left.
There are drop down lists which requires the user to click on each of them to be able to see the sublists.
I was trying to write a code so that it would click on all toggleable lists to unhide the sublists.
Using click()
on the parent element does nothing, I tried all children and subchildren of the parent element and found that this works:
x=document.querySelectorAll(".toggle").children[0].children[1];
So I tried writing a code which does click()
on all childrens, I wrote this and it worked:
x=document.querySelectorAll(".toggle");
for(i=0;i<x.length;i++){
x[i].click();
y=x[i].children;
for (j=0;j<y.length;j++){
y[j].click();
z=y[j].children;
for(k=0;k<z.length;k++){
z[k].click();
}
}
}
Since I'm a new JS learner, I tried using the for/in statement but it didn't work:
x=document.querySelectorAll(".toggle");
for(i in x){
x[i].click();
y=x[i].children;
for (j in y){
y[j].click();
z=y[j].children;
for(k in z){
z[k].click();
}
}
}
Uncaught TypeError: z[k].click is not a function at <anonymous>:9:9
I also tried forEach method and this also doesn't work:
x=document.querySelectorAll(".toggle");
var y; var z;
x.forEach(i);
function i(item, index){
item.click();
y=item.children;
y.forEach(j);
}
function j(item,index){
item.click();
z=item.children;
z.forEach(k);
}
function k(item,index){
item.click();
}
Uncaught TypeError: y.forEach is not a function at i (<anonymous>:7:4) at NodeList.forEach (<anonymous>) at <anonymous>:3:3