How to select items from a list and populate another div with the selected items using Jquery?

0

In div-students I have a list, and clicking on each student would like to fill in another div-group that I will put inside a form to register a group of students, that is, the user will select the students they want and each click that student is sent to another div. Similar to a shopping system that you enter items in the cart using Jquery

My HTML and JQUERY tags:

      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
      <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

      <link rel="stylesheet" href="style.css">

      <script>
      $(function() {
        $( "#selectable" ).selectable();
      });
      </script>

      <body>
        <div class="lista-alunos">
            <h3></i>Alunos</h3>
            <ol id="selectable">
              <li class="ui-widget-content">Aluno 1</li>
              <li class="ui-widget-content">Aluno 2</li>
              <li class="ui-widget-content">Aluno 3</li>
              <li class="ui-widget-content">Aluno 4</li>
              <li class="ui-widget-content">Aluno 5</li>
              <li class="ui-widget-content">Aluno 6</li>
              <li class="ui-widget-content">Aluno 7</li>
              <li class="ui-widget-content">Aluno 8</li>
              <li class="ui-widget-content">Aluno 9</li>
              <li class="ui-widget-content">Aluno 10</li>
              <li class="ui-widget-content">Aluno 11</li>
              <li class="ui-widget-content">Aluno 12</li>
              <li class="ui-widget-content">Aluno 13</li>
              <li class="ui-widget-content">Aluno 14</li>
            </ol>
        </div>

        <div class="lista-grupo">
          <h3>Grupo</h3>

        </div>
      </body>

CSS :

      #feedback { 
        font-size: 1.4em; 
      }
      #selectable .ui-selecting { 
        background: #FECA40; 
      }
      #selectable .ui-selected { 
        background: #F39814; 
        color: white; 
      }
      #selectable { 
        list-style-type: none; 
        margin: 0; 
        padding: 0; 
        /* SCROLL */
        height: 290px;
        overflow: auto;
      }
      #selectable li { 
        background-color: #ECECEC;
        border: 1px solid #ccc;
        margin: 3px; 
        padding: 0.4em; 
        font-size: 1.4em; 
        height: 18px; 
        cursor: pointer;
      }

      .lista-alunos, .lista-grupo{
        position: relative;
        float: left;
        display: block;
        width: 300px;
        height: 350px;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 4px;
        background-color: #fff;
      }
      .lista-grupo{
        margin-left: 15px;
      }
    
asked by anonymous 11.04.2016 / 22:52

2 answers

0

I did the following, I added a click event on the elements of the $(".ui-widget-content") list and added a <ol class="grupo-alunos"></ol> to the class="lista-grupo" div.

Jquery

$(function() {
  $( ".ui-widget-content" ).click(function(){ 
    $(".lista-grupo").append(this);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body><divclass="lista-alunos">
            <h3></i>Alunos</h3>
            <ol id="selectable">
              <li class="ui-widget-content">Aluno 1</li>
              <li class="ui-widget-content">Aluno 2</li>
              <li class="ui-widget-content">Aluno 3</li>
              <li class="ui-widget-content">Aluno 4</li>
              <li class="ui-widget-content">Aluno 5</li>
              <li class="ui-widget-content">Aluno 6</li>
              <li class="ui-widget-content">Aluno 7</li>
              <li class="ui-widget-content">Aluno 8</li>
              <li class="ui-widget-content">Aluno 9</li>
              <li class="ui-widget-content">Aluno 10</li>
              <li class="ui-widget-content">Aluno 11</li>
              <li class="ui-widget-content">Aluno 12</li>
              <li class="ui-widget-content">Aluno 13</li>
              <li class="ui-widget-content">Aluno 14</li>
            </ol>
        </div>

        <div class="lista-grupo">
          <h3>Grupo</h3>
          <ol id="grupo-alunos">
          	
          </ol>

        </div>
      </body>
    
11.04.2016 / 23:39
-1
<!DOCTYPE html>
<html>

<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
    <style type="text/css">
              #feedback { 
        font-size: 1.4em; 
      }
      #selectable .ui-selecting { 
        background: #FECA40; 
      }
      #selectable .ui-selected { 
        background: #F39814; 
        color: white; 
      }
      #selectable { 
        list-style-type: none; 
        margin: 0; 
        padding: 0; 
        /* SCROLL */
        height: 290px;
        overflow: auto;
      }
      #selectable li { 
        background-color: #ECECEC;
        border: 1px solid #ccc;
        margin: 3px; 
        padding: 0.4em; 
        font-size: 1.4em; 
        height: 18px; 
        cursor: pointer;
      }

      .lista-alunos, .lista-grupo{
        position: relative;
        float: left;
        display: block;
        width: 300px;
        height: 350px;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 4px;
        background-color: #fff;
      }
      .lista-grupo{
        margin-left: 15px;
      }
    </style>
    <script>
    $(document).ready(function() {
        $("#selectable").selectable({
            stop: function(e, ui) {
                $(".ui-selected").each(function(index, el) {
                    var id = $(el).attr('id');
                    var txt = $(el).html();
                    var li = $("<li />", {
                        "id":id,
                    }).html(txt);

                    $(li).appendTo('.lista-grupo');
                });
            },
        });
    });   
    </script>
</head>

<body>
    <div class="lista-alunos">
        <h3></i>Alunos</h3>
        <ol id="selectable">
            <li class="ui-widget-content" id="Aluno 1">Aluno 1</li>
            <li class="ui-widget-content" id="Aluno 2">Aluno 2</li>
            <li class="ui-widget-content" id="Aluno 3">Aluno 3</li>
            <li class="ui-widget-content" id="Aluno 4">Aluno 4</li>
            <li class="ui-widget-content" id="Aluno 5">Aluno 5</li>
            <li class="ui-widget-content" id="Aluno 6">Aluno 6</li>
            <li class="ui-widget-content" id="Aluno 7">Aluno 7</li>
            <li class="ui-widget-content" id="Aluno 8">Aluno 8</li>
            <li class="ui-widget-content" id="Aluno 9">Aluno 9</li>
            <li class="ui-widget-content" id="Aluno 10">Aluno 10</li>
            <li class="ui-widget-content" id="Aluno 11">Aluno 11</li>
            <li class="ui-widget-content" id="Aluno 12">Aluno 12</li>
            <li class="ui-widget-content" id="Aluno 13">Aluno 13</li>
            <li class="ui-widget-content" id="Aluno 14">Aluno 14</li>
        </ol>
        <a id="finalizar" title="">Finalizar</a>
    </div>
    <div class="lista-grupo">
        <h3>Grupo</h3>
    </div>
</body>

</html>
    
12.04.2016 / 00:05