I want to disable click on magento 2 color swatch but they are not working if one color is here i use this code in swatch-renderer.js file but they are not working

      // Connect Tooltip
            .find('[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]')

        // Hide all elements below more button
        $('.' + classes.moreButton).nextAll().hide();

        // Handle events like click or change

        // Rewind options

        //Emulate click on all swatches from Request

        var swatchLength = $('.swatch-option.color').length; // if color attribute 
        if(swatchLength == 1){

2 Answers 2


You can disable options after click first item:

  • this code is working in console panel but not working in my swatch-renderer.js file. Sep 2, 2020 at 7:54
  • you need to put after swatches was rendered Sep 2, 2020 at 8:12
  • yes I added your code but code not working can you send me right place for this code Sep 2, 2020 at 11:12
  • update your question to add where are you adding your code. Sep 2, 2020 at 11:14

A bit late in the day on this one, however this should have worked for you

 const parent = document.querySelector(".swatch-opt");
    parent.addEventListener("click", function(e) {
        const child = e.target.matches(".swatch-option, .swatch-option *");
        if (child) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.