Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: Leguim en 27 Febrero 2019, 04:48 am



Título: [Pregunta]: Obtener clases con JQUERY
Publicado por: Leguim en 27 Febrero 2019, 04:48 am
Buenas noches!

Me gustaría saber como podría obtener las clases de JQUERY para manipularlas con números según su posición, explico.. en las clases de javascript puedo manipularlas según en el orden que estan en la pagina.

Es decir, digamos... que existe la clase "test" (<p class="test">txt</p>)

bueno yo con el test[2].style.color = "red" cambio a color rojo el segundo elemento con esa clase, como podría hacerlo pero con JQUERY?


Título: Re: [Pregunta]: Obtener clases con JQUERY
Publicado por: EdePC en 27 Febrero 2019, 12:52 pm
Saludos,

- Me parece que es igual, en el libro jQuery Pocket Reference dice:

Código
  1. var paras = $("p");
  2. paras.first() // Select only the first <p> tag
  3. paras.last() // Select only the last <p>
  4. paras.eq(1) // Select the second <p>
  5. paras.eq(-2) // Select the second to last <p>
  6. paras[1] // The second <p> tag, itself

- Y para establecer estilos se sigue esta sintáxis:

Código
  1. $("h1").css("font-weight"); // Get font weight of 1st <h1>
  2. $("h1").css("fontWeight"); // Camel case works, too
  3. $("h1").css("font"); // ERROR: can't query compound style
  4. $("h1").css("font-variant", // Set style on all <h1> tags
  5.            "smallcaps");
  6. $("div.note").css("border", // Okay to set compound styles
  7.                  "solid black 2px");
  8. // Set multiple styles at once
  9. $("h1").css({ backgroundColor: "black",
  10.              textColor: "white",
  11.              fontVariant: "small-caps",
  12.              padding: "10px 2px 4px 20px",
  13.              border: "dotted black 4px" });
  14. // Increase all <h1> font sizes by 25%
  15. $("h1").css("font-size", function(i,curval) {
  16.             return Math.round(1.25*parseInt(curval));
  17. });


Título: Re: [Pregunta]: Obtener clases con JQUERY
Publicado por: Leguim en 28 Febrero 2019, 05:17 am
Saludos,

- Me parece que es igual, en el libro jQuery Pocket Reference dice:

Código
  1. var paras = $("p");
  2. paras.first() // Select only the first <p> tag
  3. paras.last() // Select only the last <p>
  4. paras.eq(1) // Select the second <p>
  5. paras.eq(-2) // Select the second to last <p>
  6. paras[1] // The second <p> tag, itself

- Y para establecer estilos se sigue esta sintáxis:

Código
  1. $("h1").css("font-weight"); // Get font weight of 1st <h1>
  2. $("h1").css("fontWeight"); // Camel case works, too
  3. $("h1").css("font"); // ERROR: can't query compound style
  4. $("h1").css("font-variant", // Set style on all <h1> tags
  5.            "smallcaps");
  6. $("div.note").css("border", // Okay to set compound styles
  7.                  "solid black 2px");
  8. // Set multiple styles at once
  9. $("h1").css({ backgroundColor: "black",
  10.              textColor: "white",
  11.              fontVariant: "small-caps",
  12.              padding: "10px 2px 4px 20px",
  13.              border: "dotted black 4px" });
  14. // Increase all <h1> font sizes by 25%
  15. $("h1").css("font-size", function(i,curval) {
  16.             return Math.round(1.25*parseInt(curval));
  17. });

Me sirvio! era :eq(X) x es numero cualquiera, GRACIAS!