jQuery – Slow SelectorsPublished: Apr 01, 2017 22:37:55
Physical Link: jQuery – Slow Selectors
Recently I was experiencing slow jQuery functions. Slow jQuery was especially slow as I added more elements to the page and especially in Internet Explorer and FireFox. I was not surprised by the browsers being slower than others, but the fact that the jQuery was slower than it should was a surprise.
It turns out it was the selector that I had been using; $(“#ElementID:visible”) was slow very slow. In a function that did nothing much, it ended up taking 10 seconds to run. I tried the selector $(“#ElementID”) and it ended up running is less than a second. A developer that I had been working with thought maybe for some reason that it was the :visible filter that was applying, but I needed it. I looked for another way to get the same result and found the .filter method. It turns out that $(“ElementID”).filter(“:visible”) made my function run in less than a second.
Do Not Use: $(“#ElementID:visible”) – Slow
Do Use: $(“ElementID”).filter(“:visible”) – Fast
The post jQuery – Slow Selectors appeared first on Software Developer In London.
Author: Andrew Pallant
Categories: Developement, jQuery, Web