1

I'm in a position where I'm dealing with a large and unwieldy document with a lot of content dynamically generated from various sources other than jQuery. The problem is that some of this content isn't picked up by jQuery's selectors in IE6 & 7.

I know that Sizzle uses some nasty but necessary evils to make legacy IE's DOM traversible. The question is, how and when are these helper attributes initialised, and how can I force it to re-parse new DOM to expose it to jQuery?

Community
  • 1
  • 1
Barney
  • 16,181
  • 5
  • 62
  • 76
  • What kind of selectors are you using that don't work in IE6/7? – Ian Mar 22 '13 at 18:22
  • Class-based ones, weirdly. Sadly (expectedly?) the test case is too huge and inherently spaghetti-like to be able to reproduce. – Barney Mar 22 '13 at 18:25
  • Sorry, I keep re-reading your question and realizing what you meant. I think I missed the part about "content dynamically generated from various sources other than jQuery", which creates the problem – Ian Mar 22 '13 at 18:28
  • What do you mean with "force it to re-parse new DOM"? A selector traverses the DOM when it is called. – a better oliver Mar 22 '13 at 18:54
  • 1
    @zeroflagL in old IEs, native DOM traversal is woefully inadequate, so Sizzle extends the elements in the document with properties like `nodeIndex`, `sizset`, `sizcache` to map to its own internal cache for more semantic relationships, a kind of extra layer on the DOM to traverse. If you use nothing but jQuery, its DOM manipulation methods will update these properties as required as you go along. But when DOM is injected from another source, these aren't added and Sizzle will miss elements when called. I'm looking for a way to re-parse the entire document and refresh those bindings. – Barney Mar 22 '13 at 19:01
  • @Barney I understand what you're saying...I think using the term "reparse" is the "confusing" part. – Ian Mar 22 '13 at 19:16
  • @Ian elaboration was for zeroflagL — but I know, re-parse is horribly ambiguous. Can you think of a better term (my previous comment is way too verbose)? – Barney Mar 22 '13 at 19:30
  • Got that, but I can't confidently confirm the "miss elements" part. An offer: present us your original problem (what content is not picked up?) and thousands of StackOverflow users will find one or more solutions. Wouldn't that be great? ;) – a better oliver Mar 22 '13 at 19:30
  • @zeroflagL sorry, misunderstood your question. I know "show us the code" makes for more sympathetic responses. Sadly (expectedly?) the test case is too huge and inherently spaghetti-like to be able to reproduce (although I will give it a shot over the weekend). Still, an arbitrary answer to "how can I force it to re-parse new DOM to expose it to jQuery?" would be cool… – Barney Mar 22 '13 at 19:32
  • @Barney I know the explanation was for zeroflagL, I was just chiming in :) I'm not sure if it's better, but "refresh". That's no good though, I don't know :( It's such a weird subject, since it's only in oldIE... – Ian Mar 22 '13 at 19:33
  • I think a possibly good explanation would be: when jQuery is used to insert/modify the DOM, it automatically adds attributes to elements (like the link that the OP provided) to make certain selectors work (with Sizzle) in older versions of IE. When you insert/modify the DOM with other libraries or vanilla Javascript, jQuery has no idea, and can't account for it and do its normal workflow for such things. The OP is asking how to have jQuery "reparse" or "refresh" its DOM "calculations" for oldIE – Ian Mar 22 '13 at 19:35
  • @Ian: (and Barney) I don't know if the current version of sizzle still adds attributes to elements. It has a cache, though. Anyway, all code I tried so far does not confirm the "miss elements" theory. Maybe it happened with older versions. – a better oliver Mar 22 '13 at 19:45
  • @zeroflagL Hmm good point, I just took the OP's word for it. I rarely work with IE7, but definitely remember seeing jQuery attributes on them. I forget how long ago/what version... – Ian Mar 22 '13 at 19:53

0 Answers0