I know getElement works on elements not in the DOM.
var test = new Element('div', {html: '<a><span>blah</span></a>'});
test.getElement('a').set('href', 'x');
document.body.grab(test);That should work fine. On Thu, Jun 18, 2009 at 3:16 PM, jonlb <[email protected]> wrote: > > Will getElement() only work if the containing element is in the DOM? > > For instance, I have this code (in a class): > > processTemplate: function(template,classes,container){ > var h = new Hash(); > var element; > if ($defined(container)){ > element = container.set('html',template); > } else { > element = new Element('div',{html: template}); > } > classes.each(function(klass){ > var el = element.getElement('.'+klass); > if ($defined(el)){ > h.set(klass,el); > } > },this); > return h; > } > > > What this is suppossed to do is to take a passed in template as a > string and create a DOM object we can search in. Then it takes the > array of CSS class names to search for and tries to find them in the > element. If it does, it should add it to the hash which is then passed > back to the caller. However, when I run this it is not working. I'm > calling it like so: > > var template = '<label class="class1"></label><input class="class2">"; > var classes = ['class1','class2']; > var container = new Element('div'); > var els = processTemplate(template, classes, container); > > and els is coming back with no elements in it. > > Can anyone see where this isn't working? I'm testing this in the > Clientcide interactive framework and am verifying all the proper > dependencies are loading including Selectors.js. > > Any help would be appreciated. > > Thanks, > jonlb >
