Javascript very slow on safari mobile [closed]

1

In my application has a javascript siples to increment a field, the problem that in the safari gets ultra slow almost does not work, while in the chrome works perfectly. Is there something to do to run normal on safari?

js:

$("#aumentaDesconto").click(function () {
var input = $("#txtDesconto")[0];
var desconto = parseInt(input.value, 10) + 1;
input.value = desconto;

});
    
asked by anonymous 14.04.2015 / 22:13

2 answers

1

The only thing I see optimizing here is removing jQuery and doing this with pure JavaScript. It would look like this:

document.getElementById("aumentaDesconto").addEventListener('click', function () {
    var input = document.getElementById("txtDesconto");
    var desconto = parseInt(input.value, 10) + 1;
    input.value = desconto;
});

If I do not solve the problem I suggest that you put a jsFiddle that reproduces the problem so that we can analyze it.

    
15.04.2015 / 05:20
1

As you've done, the code performs a search on your HTML for the element of id txtDesconto every time #aumentaDesconto is clicked.

One way to optimize is to cache the elements that are used repeatedly, since searching DOMTree is very costly for the browser.

Try this:

var input_desconto = document.getElementById("txtDesconto"),
    aumenta_desconto = document.getElementById("aumentaDesconto");

aumentaDesconto.addEventListener("click", function () {
    input.value = parseInt(input_desconto.value, 10) + 1;
}, false);

I made a JSFiddle .

    
15.04.2015 / 23:00