<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
<style>
#div1,
#div3 {
width: 400px;
height: 300px;
border: 3px solid orange;
background: #33B2C7;
float: left;
} #head:after {
content: '';
display: block;
clear: both;
overflow: hidden;
} #div2,
#div4 {
width: 300px;
height: 200px;
border: 3px solid goldenrod;
background: #004099;
} p {
width: 200px;
height: 100px;
border: 3px solid olivedrab;
background: #0000FF;
color: white;
} .bd * {
display: block;
border: 2px solid gray;
margin-top: 20x;
} .fl {
background: orangered;
}
</style>
<script src="jquery-2.2.4.min.js"></script>
<script>
$(window).load(function() {
/*---向下遍历---*/
//查找第一层级的子元素
$('#div1').children('p').css({
'background': 'red'
});
//查找所有的子元素
$('#div1').find('p').css({
'background': 'red'
});
/*------end-----*/ /*-------向上遍历-----*/
//次层级父元素
$('a').parent('#pId').css("background", 'orange');
//所有的父元素
$('a').parents().css("border", '1px solid orange');
//父元素直到某元素
// $('a').parentsUntil($('#div3')).html("parentUntil加的");
/*---------end-------*/ /*-----同级遍历-----*/
/* siblings ,next,nextuntil,nextAll,pre, preAll, preUntil*/
//所有同级
$('h4').siblings().text(function(i, old) {
return old + "----siblings()添加的";
});
$('h4').next().text(function(i, old) {
return old + "-----next()添加的";
}) $('h4').nextAll().text(function(i, old) {
return old + "-----nextAll()添加的";
}) $('h3').nextUntil('h6', 'h5').text(function(i, old) {
return old + "------nextUntil('h6', 'h5')添加的";
}) $('h3').prev().text(function(i, old) {
return old + "-----prev()添加的";
}) $('h3').prevAll().text(function(i, old) {
return old + "-------prevAll()添加的";
})
$('h4').prevUntil('h1', 'h3').text(function(i, old) {
return old + "-----prevUntil('h1', 'h3')";
})
/*------------------*/ /*-----直接选择----*/
/*first last 【filter('p')传入选择器】 【eq(0)传入index】 【not 传入选择器]*/
var fl = $('.fl');
fl.first().html(function(i, old) {
return old + "-----first() 添加的"
}); fl.eq(2).html(function(i, old) {
return old + "-----eq(2) 添加的";
}); var p = $('p');
p.filter('#xx').html(function(i, old) {
return old + "-----filter('#xx')添加的";
});
p.not('#xx').html(function(i, old) {
return old + "-----not('#xx') 添加的的";
});
})
</script>
</head> <body>
<div id="head">
<div id="div1">div1
<div id="div2">div2
<p>
<a>Hello</a>
</p>
</div>
<p><a>机构数量工具</a></p>
</div> <div id="div3">div1
<div id="div4">div2
<p id="pId">
<a>Hello</a>
</p>
</div>
</div>
</div> <div class="bd">
<p>p</p>
<h1>H1</h1>
<h2>H2</h2>
<h3>H3</h3>
<h4>H4</h4>
<h5>H5</h5>
<h6>H6</h6>
</div> <div class="fl">
<p>直接选元素1</p>
</div>
<div class="fl">
<p>直接选元素2</p>
</div>
<div class="fl">
<p id="xx">直接选元素3</p>
</div>
<div class="fl">
<p>直接选元素4</p>
</div>
</body> </html>

  

jQuery 元素遍历的更多相关文章

  1. 前端(jQuery)(8)-- jQuery元素遍历

    1.向下遍历 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  2. javascript 常见数组操作( 1、数组整体元素修改 2、 数组筛选 3、jquery 元素转数组 4、获取两个数组中相同部分或者不同部分 5、数组去重并倒序排序 6、数组排序 7、数组截取slice 8、数组插入、删除splice(需明确位置) 9、数组遍历 10、jQuery根据元素值删除数组元素的方)

    主要内容: 1.数组整体元素修改 2. 数组筛选 3.jquery 元素转数组 4.获取两个数组中相同部分或者不同部分 5.数组去重并倒序排序 6.数组排序 7.数组截取slice 8.数组插入.删除 ...

  3. jquery元素插入、删除、清空

    1)jquery元素插入 <!--位置1--> <div id='test'> <!--位置2--> <div>测试</div> <! ...

  4. jquery $.each遍历json数组方法

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/ ...

  5. Jquery节点遍历

    jquery 节点遍历 <html> <head> <title></title> <script src="Jquery/jquery ...

  6. jQuery使用(十一):jQuery实例遍历与索引

    each() children() index() 一.jQuery实例遍历方法each() jQuery实例上的each()方法规定要运行的函数,并且给函数传入两个参数:index,element. ...

  7. jquery元素插入、删除、清空、找父子级元素

    1)jquery元素插入 <!--位置1--> <div id='test'> <!--位置2--> <div>测试</div> <! ...

  8. jQuery的遍历

    jQuery有众多的方法,但是有些方法过于累赘,所以就精简了一些重要的方法,记住这些方法的(名字,功能,参数) jQuery的遍历 1.add() 将元素添加到集合中 2.children() 返回被 ...

  9. 深入学习jQuery元素过滤

    × 目录 [1]索引过滤 [2]内容过滤 前面的话 过滤是jQuery扩展的一个重要的内容.jQuery选择器中的一个重要部分就是过滤选择器.除了过滤选择器,还有专门的元素过滤的方法.本文将详细介绍j ...

随机推荐

  1. C\C++头文件说明

    C\C++编程时候经常会遇到头文件问题而出现一系列的调试错误,下面我就简要的举例介绍一下头文件的作用,我们知道一个C\C++ 程序中开头一般都为: #include<iostream.h> ...

  2. java 集合4(迭代器)

    迭代器使用要注意的问题: 1.迭代器在遍历元素的时候注意事项: 在迭代器迭代元素的过程中,不准使用集合对象改变集合中的元素个数, 如果要添加或删除要用迭代器的方法. 2.如果使用类集合对象改变集合中的 ...

  3. 花生壳+Tomcat

    花生壳(内网穿透)新手上路 http://service.oray.com/question/1664.html 好不容易找到一篇关于“花生壳+Tomcat”的好文章,转一下,上次自己弄的时候把自己的 ...

  4. jmeter 构建一个数据库测试计划

    添加用户 第一步你想做的每一个JMeter测试计划是添加一个 线程组 元素. 的线程组 告诉JMeter的用户数量你想模拟,用户应该多长时间 发送请求,他们应该发送的请求的数量. 继续添加Thread ...

  5. python中列表的操作

    list1 = ['A' , 'B' , 'C'] list1[0] ; list1[-1] # 取第一个和最后一个元素 list1[ : ] ; list1[ : len(list1)] # 取所有 ...

  6. POJ--2158--------------Milking Grid(最小覆盖字符矩阵)---(开二维kmp)

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6169   Accepted: 2573 Desc ...

  7. Text Justification [LeetCode]

    Problem Description:http://oj.leetcode.com/problems/text-justification/ Note: Just be careful about ...

  8. Quoted-printable 编码介绍、编码解码转换

    求教,“=B9=A4=D7=F7=BC=F2=B1=A8” 这种是什么编码方式? Quoted-printable 可译为“可打印字符引用编码”.“使用可打印字符的编码”,我们收邮件,查看信件原始信息 ...

  9. 《转》---使用递归方法DataTable 绑定 TreeView

    转自:http://blog.sina.com.cn/s/blog_8944756d01016yaj.html 前台: <asp:View ID="view0" runat= ...

  10. 从java 转到 c# 知识点

    1. 重写的父类方法 必须是虚方法 用virtual 关键字修饰 而子类必须用 ovrride 关键字 java中不需要,, 2. namespace => packet using => ...