Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
aplicar css cuando el elemento antes y después de la envoltura del botón usando JS

Tengo un código pero no sé por qué no funciona, incluso si es un código simple de condición if.

 $(".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" }); } });

también probé con 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()) } });

necesito agregar el estilo css (arriba) al botón cuando tiene un div con clase .wp-block-group antes Y después.

Pero, por ejemplo, si cambio el nombre del div. wp-block-group en el html, aplica el estilo css ya que la condición siempre es verdadera sabiendo que tenemos una condición con AND , ¡no entiendo!

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Considera lo siguiente.

 $(".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" }); } });

Esto examinará los elementos anterior y siguiente y, si ambos tienen la Clase, devolverá true .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!