Last active
December 17, 2021 09:59
-
-
Save enjikaka/74ec418b971567f1c1c4ce3ab154b5b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// När sidan laddat klart | |
document.addEventListener('DOMContentLoaded', function fixaStorlek () { | |
// Hitta artikelnumrets skostorlek | |
var artNrStorlek = parseInt(document.querySelector('.ml-variant-artnr').textContent.split('-').pop(), 10); | |
// Hitta drop-down fältet på sidan | |
var dropDown = document.querySelector('.js_variant_group_field10001'); | |
// Kolla vilket objekt som är valt i drop-down fältet | |
var optionValue = document.querySelector('.js_variant_group_field10001').value; | |
// Hitta objekt | |
var optionEl = document.querySelector('.js_variant_group_field10001 option[value="'+optionValue+'"]'); | |
/// Avbryt om objekt ej hittades | |
if (!optionEl) return; | |
// Hitta skostorleken som objektet representerar | |
var dropDownStorlek = parseInt(document.querySelector('.js_variant_group_field10001 option[value="'+optionValue+'"]').textContent, 10); | |
// Om storleken för valt objekt i drop-down fältet inte matchar artikelnummer... | |
if (artNrStorlek !== dropDownStorlek) { | |
// ...välj det i objekt i listan som matchar artikelnumret. | |
dropDown.value = Array.from(document.querySelectorAll('.js_variant_group_field10001 option')).filter(o => o.textContent == artNrStorlek)[0].value; | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment