JavaScript For loop within a for loop? - Javascript loop within loop python,loop within loop r,loop within

newbie javascript question. I made sure to research as much as I could before posting here, I've tried many solutions but could be searching for the wrong thing.

I've attached an image below of the issue I have. I'm trying to retrieve everything in the dark blue boxes, but I can't identify those input tags as there is nothing unique about them, I can however identify their parent divs by the class 'f-active'. When the divs have that class they have been selected by the user which is what I am interested in. page structure

My attempt so far

var divArray = document.querySelectorAll('div.add-filter.f-active');
var arr = [];
  
  for(var i=0; i < divArray.length; i++){
    var childArray = divArray[i].children;
     // console.log(childArray);
    
    for(var i=0; i < childArray.length; i++){  
      if(childArray[i].tagName == "INPUT"){
        var catNameCollection = arr.push(childArray[i].name);
        // console.log(catNameCollection);
  }
 }
}
Answer:1

Classic for-loops usually aren't the best tool for iterating through DOM elements - they add a lot of clutter and are error-prone, especially when you have to nest them.

In your case it'd be simpler to instead modify your query to directly grab all input elements with a div.f-active parent, then extract the names by iterating through them with a forEach. For example (using ES6 or higher):

const arr = [];
// Get list of all <input> elements that have <div> element parents with class f-active.
const nodes = document.querySelectorAll('div.add-filter.f-active > input');
// Extract name from each input element matched by your selector.
nodes.forEach(node => arr.push(node.name));

Or if you're stuck using ES5:

var arr = [];
var nodes = document.querySelectorAll('div.add-filter.f-active > input');
nodes.forEach(function(node) {
    arr.push(node.name);
});

Here's a quick JSFiddle I put together to demonstrate the concept for you. (You'll need to open the console to see the result)

Hopefully that helps :)

Answer:2

on window scrolling the Tooltip should appear correctly above/below/left/right of its parent. Once I scrolled down on my Demo the position of the Tooltip brakes. How can I calculate the y-offset of ...

on window scrolling the Tooltip should appear correctly above/below/left/right of its parent. Once I scrolled down on my Demo the position of the Tooltip brakes. How can I calculate the y-offset of ...

I have the following canvas: Codepen link What I want: Equal margin on both sides of canvas without any horizontal scroll bars. Problem: margin-right property does not to work. I have seen some ...

I have the following canvas: Codepen link What I want: Equal margin on both sides of canvas without any horizontal scroll bars. Problem: margin-right property does not to work. I have seen some ...

  1. margin-right not working
  2. margin right not working css
  3. margin right not working react native
  4. margin right not working android
  5. margin right not working bootstrap
  6. margin-right not working in chrome
  7. margin-right not working in ie
  8. margin right not working in outlook
  9. margin right not working on div
  10. margin right doesn't work
  11. margin-right auto not working
  12. margin-right negative not working
  13. margin right 0 not working
  14. margin right minus not working
  15. margin-right auto not working in ie
  16. html margin right not working
  17. table margin right not working
  18. ionic margin-right not working
  19. margin-right negative value not working
  20. body margin right not working

I need to convert megabytes to the appropriate unit. parseInt(10000) * 1024 * 1024 //10485760000 byte filesize(parseInt(10000) * 1024 * 1024); // "9.77 GB" 9.77 GB seems to be wrong. When I convert ...

I need to convert megabytes to the appropriate unit. parseInt(10000) * 1024 * 1024 //10485760000 byte filesize(parseInt(10000) * 1024 * 1024); // "9.77 GB" 9.77 GB seems to be wrong. When I convert ...

  1. bytes human readable
  2. bytes human readable online
  3. bytes human readable javascript
  4. java byte human readable
  5. bytes to human readable python
  6. golang bytes human readable
  7. bytes to human readable bash
  8. bytes to human readable php
  9. bytes to human readable c#
  10. bytes to human readable calculator
  11. postgres bytes human readable
  12. byte array to human readable string
  13. java byte size human readable
  14. human readable byte count
  15. python format bytes human readable
  16. javascript format bytes human readable
  17. golang format bytes human readable
  18. python print bytes human readable
  19. c# format bytes human readable
  20. java format bytes human readable

I'm trying to crete 3 HTML collections containing all my links on a page, so I can attach 3 separate function to each categories of links. My first HTML collection is "header links", the second is "...

I'm trying to crete 3 HTML collections containing all my links on a page, so I can attach 3 separate function to each categories of links. My first HTML collection is "header links", the second is "...

  1. remove items from list python
  2. remove items from array javascript
  3. remove items from list
  4. remove items from amazon history
  5. remove items from startup windows 10
  6. remove items from apple wallet
  7. remove items from launchpad
  8. remove items from dictionary python
  9. remove items from icloud
  10. remove items from kindle library
  11. remove items from list c#
  12. remove items from etsy cart
  13. remove items from menu bar mac
  14. remove items from dock
  15. remove items from google search
  16. remove items from google drive
  17. remove items from photos
  18. remove items from pictures
  19. remove items from buy again amazon
  20. remove items from quick access