Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda