Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-11-2008, 03:00 AM   PM User | #1
rhinodog8
New Coder

 
Join Date: Aug 2008
Location: Colfax, California USA
Posts: 64
Thanks: 3
Thanked 5 Times in 5 Posts
rhinodog8 is an unknown quantity at this point
Prototype: $$('.class').childElements() how to do?

I'm Using the Prototype Javascript Framework.

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

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

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

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

Last edited by rhinodog8; 11-11-2008 at 03:55 AM..
rhinodog8 is offline   Reply With Quote
Old 11-11-2008, 02:18 PM   PM User | #2
ohgod
Regular Coder

 
ohgod's Avatar
 
Join Date: Jun 2008
Location: Ohio
Posts: 579
Thanks: 6
Thanked 69 Times in 69 Posts
ohgod is on a distinguished road
Code:
$$('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.
ohgod is offline   Reply With Quote
Old 11-11-2008, 06:11 PM   PM User | #3
rhinodog8
New Coder

 
Join Date: Aug 2008
Location: Colfax, California USA
Posts: 64
Thanks: 3
Thanked 5 Times in 5 Posts
rhinodog8 is an unknown quantity at this point
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

Code:
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'
rhinodog8 is offline   Reply With Quote
Old 11-11-2008, 10:17 PM   PM User | #4
ohgod
Regular Coder

 
ohgod's Avatar
 
Join Date: Jun 2008
Location: Ohio
Posts: 579
Thanks: 6
Thanked 69 Times in 69 Posts
ohgod is on a distinguished road
put a loop in a loop

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

so something like..

Code:
$$('li.droppable').each(function(s){ 
$$('the kids').each(function(s){ whatever(); }
});
ohgod is offline   Reply With Quote
Users who have thanked ohgod for this post:
rhinodog8 (11-13-2008)
Old 11-11-2008, 11:02 PM   PM User | #5
shufei3214494
Banned

 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shufei3214494 is an unknown quantity at this point
Unhappy liver25800

glory25800sickle25800singer25800skimp25800proton25800
shufei3214494 is offline   Reply With Quote
Old 11-13-2008, 03:05 AM   PM User | #6
rhinodog8
New Coder

 
Join Date: Aug 2008
Location: Colfax, California USA
Posts: 64
Thanks: 3
Thanked 5 Times in 5 Posts
rhinodog8 is an unknown quantity at this point
Quote:
Originally Posted by ohgod View Post
put a loop in a loop

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

so something like..

Code:
$$('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:

Code:
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});
}
);
})
})}

Last edited by rhinodog8; 11-13-2008 at 03:11 AM..
rhinodog8 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:30 AM.


Advertisement
Log in to turn off these ads.