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

343
Views
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 answers
Answer question

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 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!