Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

345
Vistas
apply css when element before and after button wrapper using JS

I have a code but i don't know why it does not working, even if it's a simple code of if condition.

   $(".btn-superimposed-wrapper").each(function () {
      if (($(this).prev(".wp-block-group")) && ($(this).next(".wp-block-group"))) {
         $(this).css({ "margin-top": "-8rem", "margin-bottom": "-6rem", "text-align": "center" });
      }
   });

i also tried with hasClass() :

 $(".btn-superimposed-wrapper").each(function () {
      if ($(this).prev().hasClass(".wp-block-group") && $(this).next().hasClass(".wp-block-group")) {
         $(this).css({ "margin-top": "-8rem", "margin-bottom": "-6rem", "text-align": "center" });

         console.log("PREV ;",$(this).prev())
         console.log("NEXT ;",$(this).next())
      }
   });

i need to add the css style (above) to button when it have a div with class .wp-block-group before AND after.

But for example if i change the name of the div.wp-block-group in the html, it style apply the css as the condition is always true knowing that we have a condition with AND, i don't understand !

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Consider the following.

$(".btn-superimposed-wrapper").each(function (i, el) {
  if ($(el).prev().hasClass("wp-block-group") && $(el).next().hasClass("wp-block-group")) {
    $(el).css({
      "margin-top": "-8rem", 
      "margin-bottom": "-6rem", 
      "text-align": "center" 
    });
  }
});

This will examine the previous and next elements and if they both have the Class, will return true.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda