Reputation: 619
I have the following html structure:
<div class="checkout-related-view__related-row last">
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--left">
<input class="checkbox related-checkbox" data-role="none" id="related-checkbox-7085508-020-01077" type="checkbox" value="10">
<label for="related-checkbox-7085508-020-01077"><span class="checkbox"></span> Old Bed or Mattress Recycling</label>
</div>
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--right">
<span class="price"><span class="currency">£</span>39</span> <a class="checkout-icon checkout-icon-info related-info" data-content="We will collect your old bed frame, mattress, divan base and headboard, and recycle as much as possible into new material."
data-html="true" data-original-title="Recycling Service" data-toggle="popover" data-trigger="focus" href="javascript:void(0)" tabindex="0" title=""><span class="visuallyhidden">Recycling Service</span></a>
</div>
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--qty">
<div class="input-combobox input-combobox__with-qty" data-label="Qty" data-range-max="1" data-range-min="0">
<span class="input-combobox__label">Qty</span>
<input class="input-combobox__text input-qty" name="related_products[7085508][10][qty]" type="text" value="0">
</div>
</div>
</div>
I've try using JS to change the QTY. Unfortunatelly there is no luck. Please note that the code has no ID. Is there any way how I can set the value using name or class?
The code I've tried and didn't work is :
document.getElementsByClassName("input-combobox__text input-qty").value="1";
Can you please help?
Upvotes: 0
Views: 65
Reputation: 1148
getElementsByClassName
returns an array of elements, and you can't apply value
to an array. Instead, grab the first item in the returned array:
document.getElementsByClassName("input-combobox__text input-qty")[0].value = "1";
Upvotes: 1
Reputation: 136249
document.getElementsByClassName
returns an array of elements, if you want to set the value
of the first match do so
document.getElementsByClassName("input-combobox__text input-qty")[0].value="1";
Upvotes: 1