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

jQuerysiblings()方法

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


下面的示例将突出显示<p>元素的同级元素,<h1>并<ul>通过.highlight在准备好文档的类中添加类。


例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery siblings() Demo</title>
<style>
    .highlight{
        background: yellow;
    }        
</style>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
    $("p").siblings().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
友荐云推荐