When the page loads the first time the links don't work
Hi I have the following code with Jquery, and when the fee the first time in the browser and I click on the links do not work but if I click several times all goes well, this happens.
The first time when I clic on the link "Move me" you can see in the page: Resultado = filaX.undefined and nothing happen but the second time whe I clic on the link work fine
This is the code:
- <html>
-
- <head>
- <link rel="stylesheet" href="css/bootstrap.min.css">
- <!-- Optional theme -->
- <link rel="stylesheet" href="css/bootstrap-theme.min.css">
- <!-- Latest compiled and minified JavaScript -->
- <script src="js/bootstrap.min.js"></script>
- <script src="jquery-1.11.2.js"></script>
- <script>
- $(document).ready(function() {
- $(".filaMover").click(function() {
- var row = $(this).closest("li");
- $("p").append("<b>" + row.attr("id") + "</b>.");
- $("p").append("<b>" + row.parent().attr("id") + "</b>.");
- var lista = row.parent();
- row.detach();
- if (lista.is("#lista1")) {
- $("#lista2").append(row);
- } else {
- $("#lista1").append(row);
- }
- row.fadeOut();
- row.fadeIn();
- });
- });
- </script>
- <meta charset="utf-8">
- <title>This is a jquery test</title>
- </head>
-
- <body>
- <p>resultado = </p>
- <ul id="lista1" style="display: inline" class="displayTable list-group">
- <li id="fila1" class="list-inline">
- <div style="float:left"> FILA 1 </div>
- <div style="float:left"> FILA 1 </div>
- <div>
- <a href="#" id="fila1Mover" class="filaMover"> Move Me</a>|
- </div>
- </li>
- <li id="fila2" class="list-inline">
- <div style="float:left"> FILA 2 </div>
- <div style="float:left"> FILA 2 </div>
- <div>
- <a href="#" id="fila2Mover" class="filaMover"> Move Me</a>|
- </div>
- </ul>
- </li>
- <li id="fila3" class="list-inline">
- <div style="float:left"> FILA 3 </div>
- <div style="float:left"> FILA 3 </div>
- <div>
- <a href="#" id="fila3Mover" class="filaMover"> Move Me</a>|
- </div>
- </li>
- </ul>
- <caption>Lista2 2</caption>
- <ul id="lista2" style="background-color: Yellow; margin-top: 30px;" class=" displayTable">
- </ul>
- </body>
-
- </html>
Please help