there is a code $('.method_delivery div.method_item:eq(3)').show(); which shows a field with a radio button how to imitate clicking on it?

  var sum = parseInt($('.b_b_price').text().replace(' ', '').replace(',', '.')); if (sum < 1000) { $(".basket_b_oform ").html("<p style='color: red ;background: white; height: 100%;text-align: center;'>Оформление доступно при сумме заказа свыше 1000 руб</p>"); $('.method_delivery div.method_item:eq(3)').hide(); $('.method_delivery div.method_item:eq(2)').show().click();; }else if(sum >= 1000 && sum <= 10000) { $('.basket_buy.cb').prepend("<div class='test'style='color: red ;background: white; height: 100%;text-align: center; padding-bottom: 10px;'> При заказе до 1000 руб. к сумме заказа прибавляется 500 руб. за доставку до транспортной компании </div>"); $('.method_delivery div.method_item:eq(2)').hide(); $('.method_delivery div.method_item:eq(3)').show().click();; }else { $('.method_delivery div.method_item:eq(3)').hide(); $('.method_delivery div.method_item:eq(2)').show().click();; } }); 
  • $ (selector) .trigger ('click') watched? - ddeadlink
  • one
    You'd better have provided a full obbotchik in which .show () - Cheg
  • what meaning do you put in .replace(',', '.') inside parseInt ? - Igor
  • What does not work in the above code? - Igor
  • 2
    @gbrgbr all these details should be initially indicated in the question, and not wait until you get them out of you - Cheg

2 answers 2

It is necessary to click an input, not a diva. Assuming that the radio button inside the div.method_item one:

 $('.method_delivery div.method_item:eq(2)').show().find("input[type='radio']").click(); 
  • Thanks, very grateful - user217852

It is logical that it will be something like this:

 $('.method_delivery div.method_item:eq(3)').click(); 

If immediately after the appearance, then you can chain:

 $('.method_delivery div.method_item:eq(3)').show().click(); 
  • this way .trigger ('click') does not work either - user217852
  • @gbrgbr what are the errors with this? for understanding, you need a minimally reproducible example of your code - ddeadlink
  • .show () what to do? - user217852
  • @gbrgbr if you need a click after a certain element appears, then the show method has a callback function to implement this behavior, or show the code - ddeadlink
  • yes you need a click after the appearance of this element here $ ('. method_delivery div.method_item: eq (3)'). show () - user217852