prepare123 prepare123 - 7 months ago 6
HTML Question

how to get element by tags +5th value using selector

<table>
<tbody>
I WANT it => <input type="hidden" name="prodCd_8801043014830" id="prodCd_8801043014830" value="8801043014830">
<input type="hidden" name="itemCd_8801043014830" id="itemCd_8801043014830" value="001">
<input type="hidden" name="categoryId_8801043014830" id="categoryId_8801043014830" value="C001001700010001">
<input type="hidden" name="maxQty_8801043014830" id="maxQty_8801043014830" value="20">
<input type="hidden" name="minQty_8801043014830" id="minQty_8801043014830" value="1">
<tr>
<-- CONTENTS-->
</tr>

I WANT it => <input type="hidden" name="prodCd_8801043015738" id="prodCd_8801043015738" value="8801043015738">
<input type="hidden" name="itemCd_8801043015738" id="itemCd_8801043015738" value="001">
<input type="hidden" name="categoryId_8801043015738" id="categoryId_8801043015738" value="C001001700010004">
<input type="hidden" name="maxQty_8801043015738" id="maxQty_8801043015738" value="31">
<input type="hidden" name="minQty_8801043015738" id="minQty_8801043015738" value="1">
<tr>
<-- CONTENTS-->
</tr>


HI I want get elements in first and 1+5n input hidden tags values . there are between hidden tag groups TR tag and input hidden tags not has container.

i tried 2ways but they returns wrong values except only first value

Document doc=Jsoup.connect("URL").timeout(5000).get();
a is integer value

for(int a=0;a<10;a++){

int n = 0+5a

1.Elements testattrval =
doc.select("table tbody input[type=hidden]:eq("+n+")");

2.Elements testattrval = doc.select("table tbody input[type=hidden]:nth-child(+"n+")");

}

Answer

For iterating through a collection of object in jquery, you can use the .each() method. If you specifically want every 5th value, check if the index of the item is divisible by 5.

$("input[type='hidden']").each(function (index){
    if(index % 5 === 0){
      console.log($(this).val());
    }
});

Here I am logging the value of the input element to the console window.