Round function does not work with infinite scroll

Asked

Viewed 73 times

0

I used following Javascript function to round up discount values presented in my store:

function limparClasse(classe) {
    var elementos = document.querySelectorAll('.' + classe);
    for (var i = 0; i < elementos.length; i++) {
        var elemento = elementos[i];
        var string = elemento.innerHTML;
        var novaString = string.split('%');
        var arredondamento = parseInt(novaString[0], 10);
        var resultado = arredondamento + '%' + novaString[1];
        elemento.innerHTML = resultado;
    }
}


limparClasse('vtex-cpShow');

It worked, but only on products that were initially loaded.

How my website has scroll infinite, when we scroll the mouse and load the next products of the page, the script does not round up product values.

How should I proceed to adjust my rounding function and start calling the function every time I load a product and not every time I load a page?

  • The right is to call this function "every time" that load some product. The way it is, you call the function once and it "looks for the elements" in the DOM and makes the rounding. As the elements are loaded according to the scroll, you need to call the function again. Most likely to restructure its function so that it doesn’t have to go through the entire DOM when it loads 1, or 2 products... Edit your question and post the code of its products and the function that carries them to facilitate the response of colleagues...

  • Good morning... I don’t know where to find these messages you requested... unfortunately I don’t understand about JS and I’m trying to resolve this issue in the effort... can help me?

  • @Lipespry-defolga- goodnight... I edited the question and includes the products page code and also the function of the infinite scroll... now can instruct me how to adjust my rounding function?

  • "- Follows function used for infinite scroll." its "function" (this code block) is incomplete; "-Also follow the code of the products page." Where, on this page, is declared the function you posted to "round"? Where on this page are the elements with the class vtex-cpShow that you use in function call: limparClasse('vtex-cpShow');? There’s no way to reproduce your code that way...

  • Good afternoon @Lipespry-defolga- now I’ve done it the right way?

  • Still wrong?! :/

  • Turns out it’s a lot of code to debug and hard to reproduce. It is no use to fill the question with code and think that someone will waste a lot of time to solve the problem of your code. Because hardly a supposed answer will help others with the same problem in the future...

  • Sorry friend, it’s just that I don’t really know about the subject and I’m breaking my head to solve... if it’s but easy to understand, follow example in practice: artesintonia.com.br/ sculptures/ animals

  • Note your question. Imagine that you are on the other side. There are several services: edit your question to correct formatting errors; review all your code in order to find a good solution; come back here and formulate an answer with the solution. In the middle of this path, I edited your question and corrected the formatting errors. Until I came across incomplete codes. Then, later, you re-edit the question by adding another truck of codes. Then it all starts from scratch... Recommended reading: How to ask a good question?.

  • I totally understand, so I apologize for the work I gave you, it is no longer necessary to waste your time with me... I will continue researching "how to call the function whenever you load a product"... Thank you for all your attention.

  • I sent you an email, if you can take a look there... I need someone to perform 2 corrections on my site via js, remunerated... reply me there... Thank you!

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.