I found that the $.each is very slow and makes problems to the web pages if containing lot of various jQuery effects.
I'd like to know if there is a good alternative to the $.each, for example:
$('ul li').each(function() {
var singleLi = $(this);
});
without the hover, how can I do the same without using each?
Thanks.
If you want an actual alternative to "$.each()", just use a "for" loop:
var liElements = $('ul li');
for (var i = 0; i < liElements.length; ++i) {
var li = liElements[i];
// ... lots of various jQuery effects ...
}
The suggestions that you can skip ".each()" and just use ".hover()" directly are correct, but they miss the point: those jQuery routines will perform a ".each()" internally anyway.
I doubt that switching from "$.each()" to the "for" loop will all by itself make much of a difference, however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With