0

I can only target with a class and need to add a "data-shipping-method" parameter to the class. Here's what I'm trying...

    if (document.getElementsByClassName('div.radio-wrapper[data-shipping-method="shopify-Free%20FedEx%20Ground-0.00"][0]')) {
document.getElementsByClassName('div.radio-wrapper[data-shipping-method="shopify-FedEx%20Ground-19.00"][0]').style.visibility = 'hidden';
}

But console says: "Uncaught TypeError: Cannot set property 'visibility' of undefined"

webguy
  • 664
  • 10
  • 27
  • The element does not exist at the time you're running this code. Ensure that the element exists before changing its visiblity, and ensure you're using the correct selector. – gabriel.hayes Nov 01 '19 at 18:53
  • `getElementsByClassName` returns a list of elements not a single element. So you to iterate through each element using loop. – Maheer Ali Nov 01 '19 at 18:54
  • Note that `getElementsByClassName returns an array of elements. – Jay Buckman Nov 01 '19 at 18:54
  • I wrapped my code in "window.addEventListener('DOMContentLoaded', (event) => {" but still get the same error. As to getElementsByClassName returning an array, that's why I have [0] after the element. – webguy Nov 01 '19 at 19:08
  • I had the [0] for the array in the wrong place. Fixing it took care of the error, but the div is still not being hidden. I wrapped my code in "window.addEventListener('DOMContentLoaded', (event) => {" to make sure the element was in the DOM. Thoughts? – webguy Nov 01 '19 at 19:13
  • The div is still not being hidden. I wrapped my code in "window.addEventListener('DOMContentLoaded', (event) => {" to make sure the element was in the DOM. Thoughts? – webguy Nov 06 '19 at 23:45

0 Answers0