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