Stop the radio button, working several times

Sorry, but the new jQuery did not read, but could not find a solution.

I have a switch that when clicked starts some jQuery:

<input type="radio" id="op5" value="1" name="options2" class="custom" />

When you click this button, the following jQuery appears to perform several actions on the page

    jQuery('#op5').click(function () {
        $('input[type=checkbox]').trigger('click');
        $(".white").attr('class', 'white checked');
        $(".blue").attr('class', 'blue checked');
        $(".sub_label").attr('class', 'sub_label')
        $(".sub_label checked").attr('class', 'sub_label')

    });

Currently, if the user repeatedly clicks on the switch that he launches, and uncheck the boxes when he launches the line

$('input[type=checkbox]').trigger('click');

Is there a way I can stop the code in my jQuery function a second time?

JS Fiddle - https://jsfiddle.net/jqh3L8t6/

+4
source share
1 answer

.one() jquery, . .addClass() attr()

jQuery('#op5').one("click" , function () {
          $('input[type=checkbox]').trigger('click');
          $(".white").addClass('white checked');
          $(".blue").addClass('blue checked');
          $(".sub_label :checked").addClass('sub_label')

 });

Fiddle

+7

Source: https://habr.com/ru/post/1583761/


All Articles