...

View Full Version : Prototype: $$('.class').childElements() how to do?



rhinodog8
11-11-2008, 03:00 AM
I'm Using the Prototype Javascript Framework.

So how can I get something like
$$('.class').childElements() to return element nodes, not an array.

right now I'm using
$('id').childElements() but i want it to apply to every element with a certain class.

right now it says
$$('.class').childElements is not a function.

I've also tried (gave the body tag an id of body)
$('body').getElementsByClassName('class').childElements() but that doesn't work either.

ohgod
11-11-2008, 02:18 PM
$$('li.droppable').each(function(s){ alert( s.identify(); });

that would iterate through the returned array and alert for each id for li elements with droppable as a class. tinker with it, you'll get the idea.

rhinodog8
11-11-2008, 06:11 PM
yeah, I know how to do that, what I need to do is apply an each function on the children elements of a certain class.

This my entire code right now, but it relys on a spefic id to do it


function accordion(){
var children = $('accordion').childElements();
var i = 1;

children.each(function(a) {a.setAttribute("value", i++);

if (i % 2 == 0) {a.setStyle({backgroundColor: '#d4d4d4', padding:'0px 0px 0px 50px'});
a.insert(Builder.node('div', {className: 'arrow'}))};

if (i % 2 == 1) {Effect.BlindUp(a, {duration:0.5})};

$$('.arrow').invoke('observe', 'click', function(){
Effect.toggle(this.parentNode.next(),'slide', { duration: 0.5});
});

$$('.left').each(function(l){l.setStyle({textAlign:'left'})})
$$('.right').each(function(r){r.setStyle({textAlign:'right'})})
})
}

the bold part needs to select all the child elements of any element with the class 'accordion'

ohgod
11-11-2008, 10:17 PM
put a loop in a loop

where i put that alert, put a second $$() with an each as well.

so something like..


$$('li.droppable').each(function(s){

$$('the kids').each(function(s){ whatever(); }
});

shufei3214494
11-11-2008, 11:02 PM
glory25800 (http://glory25800.blog.com)sickle25800 (http://sickle25800.blog.com)singer25800 (http://singer25800.blog.com)skimp25800 (http://skimp25800.blog.com)proton25800 (http://proton25800.blog.com)

rhinodog8
11-13-2008, 03:05 AM
put a loop in a loop

where i put that alert, put a second $$() with an each as well.

so something like..


$$('li.droppable').each(function(s){

$$('the kids').each(function(s){ whatever(); }
});

Oh wow, can't believe I didn't think of that. Thanks!

Hers my code now if anyone wanted to know:


function accordion(){
var i = 1;
$$('.class').each(function(c){

c.childElements().each(function(a) {a.setAttribute("value", i++);

if (i % 2 == 0) {
a.setStyle({backgroundColor: '#d4d4d4', padding:'0px 0px 0px 50px'});
a.insert(Builder.node('div', {className: 'arrow'}))
};

if (i % 2 == 1) {
Effect.BlindUp(a, {duration:0.5});
a.setStyle({fontSize: '20px', textAlign: 'center', padding:'5px'})};

$$('.arrow').invoke('observe', 'click', function(){
Effect.toggle(this.parentNode.next(),'slide', { duration: 0.5});
}
);
})
})}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum