0

I want to target a label which is part of a CMS system. The simplest way would be to use "for"

I can target the input instead and then the sibling, I just thought I would ask if this is possible.

The main reason I want to do this is to remove the (+£5.00)

<input type="radio" autocomplete="off" name="product_option[54]" value="107" id="option-value-107" onchange="doAjaxPrice(108,'#option-54');">
<label for="option-value-107">1kg(+£5.00)</label>
Eoin
  • 1,413
  • 2
  • 17
  • 32
  • 1
    Does this answer your question? [Find an element in DOM based on an attribute value](https://stackoverflow.com/questions/2694640/find-an-element-in-dom-based-on-an-attribute-value) – Justinas Jun 22 '22 at 12:28
  • @Justinas yes I think so, thank you. I just didn't know what to call them. Is "attribute value" the correct name? – Eoin Jun 23 '22 at 13:10
  • Yes, `for` is attribute, and `option-value-107` is this attribute's value – Justinas Jun 23 '22 at 16:23

2 Answers2

4

Yes you can :

document.querySelector('label[for="option-value-107"]');
nem0z
  • 1,060
  • 1
  • 4
  • 17
1

You can use square brackets and specify attribute and it's value to select an element

document.querySelector('label[for*=option-value-107]')
Nitin Ramnani
  • 314
  • 1
  • 7