descendants()

功能

获取指定元素的子代, (可选) 选择器。

语法

finder.descendants(elm, selector)

参数

  • elm
    HTMLElement对象,指定对象HTML元素
  • selector
    一个匹配元素的选择器表达式

范例

Example: 查找所有表单下的所有input后代元素。

<!DOCTYPE html>
<html>

<head>
    <style>
    body {font-size: 14px; }
    form {border: 2px green solid;padding: 2px;margin: 0;background: #efe; }
    div { color: red; }
    fieldset { margin: 1px;padding: 3px;}
    </style>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
    <script>
    require.config({
        baseUrl: "./",
        packages: [{
            name: "skylark",
            location: "../../../src/skylark"
        }, ]
    });
    </script>
</head>

<body>
    <form>
        <div>Form is surrounded by the green outline</div>
        <label>Child:</label>
        <input name="name" />
        <fieldset>
            <label>Grandchild:</label>
            <input name="newsletter" />
        </fieldset>
    </form>
    Sibling to form:
    <input name="none" />
    <script>
    require(["skylark/finder", "skylark/styler"], function(finder, styler) {
        finder.descendants(finder.find("form"), "input").forEach(function(node, index) {
            styler.css(node, "border", "2px dotted blue");
        });
    });
    </script>
</body>

</html>