费话不多说,直接上代码
jquery 获取元素

 1 $("#test1").parent(); // 父节点
 2 $("#test1").parents(); // 全部父节点
 3 $("#test1").parents(".mui-content");//返回class为mui-content的父节点
 4 $("#test1").children(); // 全部子节点
 5 $("#test1").children("#test1"); //返回id为test1的子节点
 6 $("#test1").contents(); // 返回id为test里面的所有内容,包括节点和文本
 7 $("#test1").contents("#test1"); //返回id为test里面的id为#test1的节点和文本
 8 $("#test1").prev();  // 上一个兄弟节点
 9 $("#test1").prevAll(); // 之前所有兄弟节点
10 $("#test1").next(); // 下一个兄弟节点
11 $("#test1").nextAll(); // 之后所有兄弟节点
12 $("#test1").siblings(); // 所有兄弟节点
13 $("#test1").siblings("#test2"); //返回id为test2的兄弟节点
14 $("#test").find("#test1"); 选中id为test后代中 id为test1的节点
View Code

注意上面的方法 返回的是jquery 集合 需要继续用jq的方法操作或取值
如果想要转为dom 直接操作的只需要 取它的下标即可
如: $("#test1").parent()[0] 返回的就是dom节点

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/milletHandsome/p/11887833.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程