0

I have:

<div class="f0">
    <div class="input-text">
        <t>Text</t>
    </div>
</div>
var h = 0;
    for(h;h<inputstext.length;h++){
        var str = 'f' + h;
        var currentDiv = document.getElementById(str);


    }

How do I get only the input-text elements value that is in f0?

Output should be Text.

Thanks.

Arr
  • 33
  • 5

1 Answers1

2

You can use the element[property*="val"] to select all elements with property beginning with "val" - in this case, any class that starts with "f", and then select their .input-text children.

Also, you're trying to get elements with id f0, when these divs are marked with class f0.

const inputs = document.querySelectorAll('[class*="f"] .input-text');
for (const element of inputs)
  console.log(element.textContent.trim());
<div class="f0">
    <div class="input-text">
        inside f0
    </div>
</div>
<div class="f1">
    <div class="input-text">
        inside f1
    </div>
</div>
Lewis
  • 4,285
  • 1
  • 23
  • 36