How about using GWTQuery? It's easy to use (very similar to your Mootols example), and it's highly optimized for speed (individually for different browser). http://code.google.com/p/gwtquery/
On Jun 24, 11:46 am, Paul Schwarz <[email protected]> wrote: > In Mootools et al. it is really easy to select all elements in the DOM > with a given attribute, such as CSS class. In Mootools this is > var listOfDivsWithClassRED = $$(".RED") > > I have a need to select all the elements on a page with a given > attribute and value and I'm trying to mimic Mootools functionality AND > speed! > > I > found:http://stackoverflow.com/questions/2406002/find-an-element-by-css-sel... > and then saw Robert > Hanson's:http://gwt-widget.sourceforge.net/docs/xref/org/gwtwidgets/client/uti... > > Robert Hanson's recursion idea seems correct to me, except in my case > the execution time is 5500ms for a typical page. Due to the structure > of my markup I know that the elements I am interested in will not > occur deeper than a certain depth on the DOM tree, so I put a > recursionMaxDepth concept into my recursion and now I'm down to > 3000ms. > > That's still too long, but I know how to solve it. The problem is (see > Robert's code) we are dealing with GWT Elements. For example, see the > lines: > c = DOM.getAttribute(element, "className"); > Element child = DOM.getChild(element, i); > > So in my case the recursive function is inspecting about 1000 elements > on the page (which is fine) but then GWT is turning each child element > into an Element just to inspect an attribute and value pair, and then > it discards the Element if it doesn't match my criteria. That's VERY > expensive. > > I need a way to spin through those 1000ish elements quickly, treating > them as "raw DOM elements", maybe Nodes, and then do the attribute > matching on those light-weight objects. If one of them matches then > GWT can turn it into a full blown Element object. > > Please set me on the right track. Node looks promising for its > lightweight child-getting facilities, but not sure how to then inspect > an attribute, and for that matter obtain an Element out of it. > > Furthermore, can anyone think of other enhancements to make this > quicker? -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
