Woppi
Woppi

Reputation: 5431

YUI Dom.getChildren

Can you change classes without id when your classes are dynamic and only the parent has an id?

I have something like:

<div id="number_block">
  <div class="one science easy left"></div>
  <div class="one science easy center"></div>
  <div class="one science easy right"></div>
</div>

I only reach this part

var number_block_children = Dom.getChildren('number_block');
for(var i=0; i < number_block_children.length; i++)
{
     /* I don't know the syntax to change class name here for every child, is it possible?
      * I can't use Dom.getElementByClassName...since the class is dynamic.
      * It's something similar to how get classname by id, only I don't have id, just parent id:
      *        Dom.get('id-name-here').className
      * I can't figure out how to do this....
      */

}

Thanks!

Upvotes: 0

Views: 1509

Answers (2)

jira
jira

Reputation: 3944

You can use getAttribute to get element classes:

var number_block_children = YAHOO.util.Dom.getChildren('number_block');
for(var i=0; i < number_block_children.length; i++)
{

    var class = YAHOO.util.Dom.getAttribute(number_block_children[i], 'class');
    var classes = class.split(' ');

}

Upvotes: 1

jebberwocky
jebberwocky

Reputation: 1089

hey you can do something like

YAHOO.util.Event.addListener(window, "load", function() {
    var number_block_children = YAHOO.util.Dom.getChildren('number_block');
    for(var i=0; i < number_block_children.length; i++)
    {
        console.log(YAHOO.util.Dom.hasClass(number_block_children[i], 'one'));
        console.log(YAHOO.util.Dom.hasClass(number_block_children[i], 'two'));
    }
});

hope it helps

Upvotes: 0

Related Questions