YUI Dom.getChildren

发布于 2024-09-27 16:25:43 字数 843 浏览 0 评论 0原文

当你的类是动态的并且只有父类有 id 时,你可以更改没有 id 的类吗?

我有这样的想法:

<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>

我只到达这部分

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....
      */

}

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萤火眠眠 2024-10-04 16:25:43

您可以使用 getAttribute 来获取元素类:

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(' ');

}

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(' ');

}
起风了 2024-10-04 16:25:43

嘿你可以做一些事情

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'));
    }
});

希望它有帮助

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文