$(function() {
   $(".open-code").each(function(i) {
        $(this).attr('id', "open" + (i + 1));
    });
    $(".hide-code").each(function(i) {
        $(this).attr('id', "hide" + (i + 1));
    });
   
   $( ".select_hide" ).change(function() {
        var id = $(this).children(":selected").attr("id");
        $(".hide-code").hide();
        var id_element2 = id.replace("open", "");
        $("#hide"+id_element2).show();
    });
   
}); 




$(function() {
   $(".odd-li").click(function() {
       $("#parraPrim > p, #listaPrim > li").css("background-color", "transparent");
       $("#listaPrim > li:odd").css( "background-color", "red"); 
   });
   $(".odd-p").click(function() {
       $("#parraPrim > p, #listaPrim > li").css("background-color", "transparent");
       $("#parraPrim > p:odd").css( "background-color", "red"); 
   });
   $(".even-li").click(function() {
       $("#parraPrim > p, #listaPrim > li").css("background-color", "transparent");
       $("#listaPrim > li:even").css( "background-color", "red"); 
   });
   $(".even-p").click(function() {
       $("#parraPrim > p, #listaPrim > li").css("background-color", "transparent");
       $("#parraPrim > p:even").css( "background-color", "red"); 
   });
   $(".clear-oddeven").click(function() {
       $("#parraPrim > p, #listaPrim > li").css("background-color", "transparent");
   });
});

$(function() {
   $(".first-li").click(function() {
       $(".seleccion").css("background-color", "transparent");
       $(".seleccion:first").css( "background-color", "red"); 
   });
   $(".eq-li").click(function() {
       var valor = $("#valorSelect").val();
       $(".seleccion").css("background-color", "transparent");
       $(".seleccion:eq("+valor+")").css( "background-color", "red"); 
   });
   $(".gt-li").click(function() {
       var valor = $("#valorSelect").val();
       $(".seleccion").css("background-color", "transparent");
       $(".seleccion:gt("+valor+")").css( "background-color", "red"); 
   });
   $(".lt-li").click(function() {
       var valor = $("#valorSelect").val();
       $(".seleccion").css("background-color", "transparent");
       $(".seleccion:lt("+valor+")").css( "background-color", "red"); 
   });
   $(".slice-li").click(function() {
       var valor = $("#valorSelect").val();
       var valor2 = $("#valorSelect2").val();
       $(".seleccion").css("background-color", "transparent");
       $(".seleccion").slice(valor, valor2).css( "background-color", "red"); 
   });
   $(".clear-li").click(function() {
       $(".seleccion").css("background-color", "transparent");
   });
});

$(function() {
   $(".tell-hidden").click(function() {
       var num = $(".seleccion2:hidden");
       alert("Los elementos escondidos son " + num.length);
   });
   $(".show-hidden").click(function() {
       $(".seleccion2:hidden").show();
   });
   $(".all-hidden").click(function() {
       $(".seleccion2").hide();
   });
   $(".clickVisibly").click(function() {
        $("li").each(function() {
            if ($(this).css("visibility") === "hidden") {
                $(this).css("visibility", "visible");
            }
        }); 
    });
   $(".clear-li2").click(function() {
       $(".seleccion2").show();
       $(".element-hidden").hide();
       $(".element-invisible").css("visibility", "hidden");
   });
});

$(function() {
   $(".div-has").click(function() {
       $(".padre-div").has("li").css("background", "red");
   });
   $(".not-has").click(function() {
       $( "#list-father li" ).not( "#has-father").css("background", "red");;  
   });
   $(".clear-li3").click(function() {
       $("li").css("background-color", "transparent");
       $(".padre-div").css("background-color", "transparent");
   });
});

$(function() {
   $(".shmi-son").click(function() {
       clear4();
       $( ".shmi-child" ).children("img").css( "border", "3px solid red" );
   });
   $(".vader-children").click(function() {
       clear4();
       $( ".vader-child").children("img").css( "border", "3px solid red" );
   });
   $(".leia-son").click(function() {
       clear4();
       $( ".leia-child>img" ).css( "border", "3px solid red" );
   });
   $(".shmi-descendant").click(function() {
       clear4();
       $( ".shmi-child" ).find("img").css( "border", "3px solid red" );
   });
   $(".vader-descendant").click(function() {
       clear4();
       $( ".vader-child img" ).css( "border", "3px solid red" );
   });
   $(".luke-sibling").click(function() {
       clear4();
       $( "#luke" ).next().children("img").css( "border", "3px solid red" );
   });
   $(".leia-sibling").click(function() {
       clear4();
       $( "#leia" ).prev().children("img").css( "border", "3px solid red" );
   });
   $(".kylo-mother").click(function() {
       clear4();
       $( "#kylo" ).parent().children("img").css( "border", "3px solid red" );
   });
   $(".kylo-ancestor").click(clear4,function() {
       clear4();
       $( "#kylo img" ).parentsUntil("#star-wars").find( ".ancestor" ).css( "border", "3px solid red" );
   });
   $(".clear-li4").click(clear4);
});

function clear4() {
    $("#star-wars img").css("border", "3px transparent");
    $("#star-wars div").css("border", "3px transparent");
}

$(function() {
   $(".input-type").click(function() {
        var allInputs = $( ":input");
        $( "#form-result" ).text( "Encontrados " + allInputs.length + " inputs." );
   });
   $(".pass-type").click(function() {
       var input = $( "input:password" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'password'." )
        .css( "color", "red" );
   });
   $(".reset-type").click(function() {
       var input = $( "input:reset" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'reset'." )
        .css( "color", "red" );
   });
   $(".radio-type").click(function() {
       var input = $( "input:radio" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'radiobutton'." )
        .css( "color", "red" );
   });
   $(".submit-type").click(function() {
       var input = $( "input:submit" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'submit'." )
        .css( "color", "red" );
   });
   $(".text-type").click(function() {
       var input = $( "input:text" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'text'." )
        .css( "color", "red" );
   });
   $(".checkbox-type").click(function() {
       var input = $( "input:checkbox" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'checkbox'." )
        .css( "color", "red" );
   });
   $(".button-type").click(function() {
       var input = $( "form input:button" ).css({
        background: "yellow",
        border: "3px red solid"
      });
      $( "#form-result" )
        .text( "Hay " + input.length + " input de tipo 'button'." )
        .css( "color", "red" );
   });
   $(".select-type").click(function() {
       var input = $( "#form-prueba option:selected" );
      $( "#form-result" )
        .text( "Has elegido la opción " + input.text())
        .css( "color", "red" );
   });
   $(".clear-form").click(function() {
       $("#form-prueba input").css({
            background: "#e7e7e7",
            color: "black",
            border: "black"
       });
   });
});

$(function() {
    $("#myListFil").click(function() {
        $( "#myList li" ).css( "background-color", "transparent" );
        $( "#myList li" ).filter( ":even" ).css( "background-color", "red" );
    });
    
    $("#myListFil2").click(function() {
        $( "#myList li" ).css( "background-color", "transparent" );
        $( "#myList li" ).filter(function() {
          return $( "strong", this ).length === 1;
        })
          .css( "background-color", "red" );
    });
    
    $("#myListFil3").click(function() {
        $( "#myList li" ).css( "background-color", "transparent" );
        $( "#myList li" ).filter(function() {
          return $( "strong", this ).length === 2;
        })
          .css( "background-color", "red" );
    });
    
    $("#myListClear").click(function() {
        $( "#myList li" ).css( "background-color", "transparent" );
    })
});