Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created January 19, 2024 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elias1435/d465cfbe7054543c1b2d8d8504b42fff to your computer and use it in GitHub Desktop.
Save elias1435/d465cfbe7054543c1b2d8d8504b42fff to your computer and use it in GitHub Desktop.
Match String and add selector by native js
<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