Created
January 19, 2024 08:16
-
-
Save elias1435/d465cfbe7054543c1b2d8d8504b42fff to your computer and use it in GitHub Desktop.
Match String and add selector by native js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener('DOMContentLoaded', function () { | |
// Get all elements with the specified class | |
var targetElements = document.querySelectorAll('.berocket_better_labels_position span.b_span_text'); | |
// Loop through each element | |
targetElements.forEach(function (targetElement) { | |
// Get the number and convert it to a float | |
var number = parseFloat(targetElement.textContent); | |
// Check if the number is below 20% | |
if (number < 20) { | |
// Add a class to the parent element with the specified class | |
var parentElement = targetElement.closest('.berocket_better_labels_position'); | |
if (parentElement) { | |
parentElement.classList.add('discount-below-tweenty'); | |
} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment