I have input
on a page where I type the zip code and can calculate the estimated value and time for delivery of a product for each region.
Clicking the calculate button will show a box loaded via Ajax with its information, the problem is that the platform has a small problem (bug) and shows 8 working days even for products that should be 4 working days . Home My goal is to do a check for if the product has a price higher than $ 149.90 it performs a function to change the text from 8 business days to 4 business days. Home The problem is that this element is not loaded right after clicking the button, it only appears when the Ajax request is completed (and I do not have access to the scripts that make this request). Home So I face problems like the user's connection speed (which is variable from one to another), and the elements do not exist right after I click the button. Home I tried to use the while loop, but I'm having problems, see the code:
window.addEventListener('DOMContentLoaded', function(){
if( document.querySelector('button[type="submit"]').textContent === 'OK' ){
document.querySelector('button[type="submit"]').addEventListener('click', function(){
var preco = /(\d+)(\,)(\d+)/.exec( document.getElementsByClassName('preco-promocional')[1].textContent );
if( preco[1] > 149 ){
while( typeof( document.getElementsByClassName('prazo')[1] ) === 'undefined' ){
while( document.getElementsByClassName('prazo')[1].textContent === '8 dias úteis' ){
document.getElementsByClassName('prazo')[1].textContent = '4 dias úteis';
}
}
}
});
}
});
The logic would be to check while this element is undefined
, and then, when it is no longer, I execute another loop to check if the text is 8 dias úteis
and while it is, it tries to change to 4 dias úteis
.
Home
Thanks for the attention