I can't make a violin jQuery.



  • Tell me how to do the click. input counted it. ID, then found the element div with the same id and that element removed the class uk-hidden

    jQuery(document).ready(function($) {
      $("input").click(function() {
        var $chek = $(this).attr('id');
        $('.result div').find($chek).removeClass('uk-hidden');
        console.log($chek);
      });
    });
    <link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.24.0/css/uikit.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="uk-width-4-10">
      <input id="check1" type="radio" name="voice" value="check1" />
      <label for="check1">Вариант 1</label>
      <br />
      <input id="check2" type="radio" name="voice" value="check2" />
      <label for="check2">Вариант 2</label>
      <br />
    </div>
    <div class="uk-width-6-10 result">
      <div id="check1" class="uk-hidden">123</div>
      <div id="check2" class="uk-hidden">123</div>
    </div>



  • Your mistake is that you use the same. id one page

    jQuery:

    $(document).ready(function($) {
      $("input").on('click', function() {
        var chek = $(this).data('id');
        $(chek).removeClass('uk-hidden');
        console.log(chek);
      });
    });
    

    HTML:

    <link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.24.0/css/uikit.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="uk-width-4-10">
      <input id="check1" data-id="#div1" type="radio" name="voice" value="check1" />
      <label for="check1">Вариант 1</label>
      <br />
      <input id="check2" data-id="#div2" type="radio" name="voice" value="check2" />
      <label for="check2">Вариант 2</label>
      <br />
    </div>
    <div class="uk-width-6-10 result">
      <div id="div1" class="uk-hidden">123</div>
      <div id="div2" class="uk-hidden">123</div>
    </div>
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2