热门关键字:
jquery > jquery教程 > jquery教程 > jQuerychildren()方法

jQuerychildren()方法

320
作者:管理员
发布时间:2021/1/29 13:58:04
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3615
jQuerychildren()方法用于获取所选元素的直接子级。


下面的示例将突出显示<ul>元素的直接子元素,即<li>通过.highlight在准备就绪的文档上添加类。


例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery children() Demo</title>
<style>
    .highlight{
        background: yellow;
    }        
</style>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
    $("ul").children().addClass("highlight");
});
</script>
</head>
<body>
    <div class="container">
        <h1>Hello World</h1>
        <p>This is a <em>simple paragraph</em>.</p>
        <ul>
            <li>Item One</li>
            <li>Item Two</li>
        </ul>
    </div>
</body>
</html>




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:jQuery
友荐云推荐