Advertisement
ikai2

option name

Sep 11th, 2022 (edited)
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.62 KB | Source Code | 0 0
  1. const products = [...document.querySelectorAll('[data-pf-type="ProductBox"]')];
  2. products.map(product =>  {
  3.     const listColors = product.querySelectorAll('[data-swatch-type="color"] > div');
  4.     listColors.forEach(option => {
  5.         const input = option.querySelector('input');
  6.         const optionLabel = product.querySelector('[data-pf-type="OptionLabel"]');
  7.         if (input.checked) {
  8.             optionLabel.innerHTML += `<span class="option-name">: ${input.value}</span>`;
  9.         }
  10.         input.addEventListener('change', () => {
  11.             const optionName = product.querySelector('.option-name');
  12.             optionName.innerHTML = `: ${input.value}`;
  13.         });
  14.     });
  15. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement