TruMan1
TruMan1

Reputation: 36118

Replace "find" for optimization in IE8?

I have a recursive jQuery function that has something like this:

parentItem.find('> div:first-child > span.c-checkbox > input[type="checkbox"]');

This runs great in Chrome, Firefox, Safari, and even IE9. With IE8 and below it is horribly slow (15+ seconds).

I found in an article that IE8 performs bad with "find": http://ethermuse.blogspot.com/2011/07/jquery-find-slow-in-ie8.html. I do not quite understand the concept. Can someone recommend a way to make this work properly in IE8?

EDIT: I tried replacing the code snippet with this in my application and I think I noticed an improvement:

parentItem.children("div:first-child").children("span.c-checkbox").children("input[type=checkbox]")

Are the selectors identical and is there a way I can measure this?

Upvotes: 2

Views: 212

Answers (2)

Greg Franko
Greg Franko

Reputation: 1770

Try to reduce the number of advanced selectors inside of find().

Try this:

parentItem.find('input:checkbox');

Upvotes: 2

Ya Zhuang
Ya Zhuang

Reputation: 4660

it's not the find problem, but you should optimize your selector expression.

the best practice is use id, cause jQuery directly call document.getElementById to select node.

if you use such things like$('.class') $(input[name=somename]), there is no directly raw javascript method to do that, and jQuery would scan all the node to find which node you want, that cause the performance problem.

to solve your problem, you'd better specify an id to your element.

OR,

maybe you can paste out your HTML, so that i can write better selector for you :)

Upvotes: 0

Related Questions