0

Script in filename.phtml

      <script>
       require(['jquery', 'jquery/ui'], function($){

                //   $('.swatch-option')[0].css('color','red');
                  $('.swatch-option').get(0).click();
                  alert('123');

        });
</script>

Error in Console

filename.html:1028 Uncaught TypeError: Cannot read property 'click' of undefined

3
  • try with this - [0].click(); Jul 10, 2019 at 10:30
  • no way, already check Jul 10, 2019 at 10:31
  • can you please check, may be (.'swatch-option').get(0) have multiple inputs. Jul 10, 2019 at 10:34

1 Answer 1

1

Add dependency 'domReady!'.

<script>
       require(['jquery', 'jquery/ui', 'domReady!'], function($){
                  $('.swatch-option').get(0).click();
                  alert('123');

        });
</script>
2
  • Cannot read property 'click' of undefined same error showing in console Jul 10, 2019 at 10:38
  • you write in file static ? Jul 10, 2019 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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