jQuery03(筛选和文档处理)

一、筛选

一.1过滤

first():获取匹配的第一个元素

$("#oDiv>ul>li").first().css("border","1px solid blue")

last():获得匹配的最后一个元素

$("#oDiv>ul>li").last().css("border","1px solid blue")


eq(N):获取匹配的第N或-N个元素

$("#oDiv>ul>li").eq(3).css("border","1px solid blue")


filter(selector):筛选出与指定表达式匹配的元素集合

 $("#oDiv>#myOl>li").filter("[title=aa]").css("background","yellow");


has(selector):筛选出包含特定特点的元素的集合

$("#oDiv>#myOl>li").has("span").css("background","yellow");


not(selector):筛选出不包含特定特点的元素的集合

 $("#oDiv>ul>li").not("[title]").css("background","red");

一.2查找

children():子标签中找

 $("#oDiv>ul").children().css("background","orange");


find():后代标签中找

$("#oDiv>#myOl").find("span").css("background","red");


parent():父标签

$("b").parent().css("background","blue");


prevAll():前面所有的兄弟标签

$("#oDiv>ul").children().eq(2).prevAll().css("background","orange");


nextAll():后面所有的兄弟标签

 $("#oDiv>ul").children().eq(2).nextAll().css("background","orange");


siblings():前后所有的兄弟标签

$("#oDiv>ul").children().eq(2).siblings().css("background","orange");

append():将内容添加到指定的元素后面

$("#oDiv>li").last().append("<a href = '#'>百度一下</a>");


appendTo():和append()颠倒

$("<a href = '#'>百度一下</a>").appendTo($("#oDiv").children().last());


prepend():将内容添加到指定元素前面

$("#oDiv>li").first().prepend("<a href = '#'>百度一下</a>");


prependTo():和prepend()颠倒

$("<a href = '#'>百度一下</a>").prependTo($("#oDiv").children().eq(2));


after():在匹配元素之后插入内容

$("#oDiv").children().filter("[title=b]").css("background","red").after("<a href = '#'>呵呵</a>");


before():在匹配元素之前插入内容

$("#oDiv").children().filter("[title=b]").before("<a href = '#'>呵呵</a>");

empty():删除匹配的元素集合中所有的子节点(不包含匹配的元素)

 $("#oDiv").children("li").css("background","red").empty();


remove():删除匹配的元素集合中所有的子节点(包含匹配的元素)

$("#oDiv").children("li").css("background","red").remove();

replaceWith():将所有匹配的元素替换成指定的内容

 $("#oDiv").find('span').css("background","red").replaceWith("<a href = '#'>超链接</a>")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值