how to select elements by name with serial

Viewed 23

Is there any way to select elements with wildcard?

Markup

<input type="text" name="variable_ebay_ean[0]" class="" value="505517254641">
<input type="text" name="variable_ebay_ean[1]" class="" value="505517254642">
<input type="text" name="variable_ebay_ean[2]" class="" value="505517254643">

and JavaScript code to select elements

let o= document.querySelectorAll("[name='variable_ebay_ean[(*)]']");
1 Answers

You can reach it using the "Starts with" selector.

let o= document.querySelectorAll("[name^='variable_ebay_ean']");

let o = document.querySelectorAll("[name^='variable_ebay_ean']");
console.log(o);
<input type="text" name="variable_ebay_ean[0]" class="" value="505517254641">
<input type="text" name="variable_ebay_ean[1]" class="" value="505517254642">
<input type="text" name="variable_ebay_ean[2]" class="" value="505517254643">

Related