I tried for 5 minutes but couldn't wrap my head around that :D Why do you need to 'pretend the elements are children of this'? What are you trying to achieve?
- ricardo On Nov 28, 2:04 pm, Mark Gibson <[EMAIL PROTECTED]> wrote: > With the follow style of markup: > > <div id="my-combo" role="combobox" aria-owns="my-list another-thing"> > </div> > > <div id="my-list" role="list"> > </div> > > I need to find the first element of type [role=list], in either the > descendants > of #my-combo, or the elements (and descendants) identified in aria- > owns. > > I was think of creating a plugin to make this easier: > > $('#my-combo').owns('[role=list]:first'); > > $.fn.owns = function(selector) { > // Gather all the id's from aria-owns attrs, appending '#' to each, > and separate with ',' > var include = $(this).filter('[aria-owns]').map(function() { > return this.getAttribute('aria-owns').replace(/([^\s]+)/g, '# > $1').replace(/\s+/g,','); > }); > > if (include.length) { > // Find all the referenced elements > var owned = $(Array.prototype.join.call(include,',')); > > // HELP NEEDED HERE! > // Here I need to pretend that the 'owned' elements are also > children of 'this' > // FakeElement(owned + this.children()).find(selector) > // or > // owned.add(this.children()).findIncSelf(selector) > } else { > return this.find(selector); > } > > }; > > I'm puzzled as to how to combine the owned elements and the > descendants of the > context elements, and find the using the requested selector. > Any ideas? > > Cheers > -Mark