jquery 获取元素(父节点,子节点,兄弟节点)

费话不多说,直接上代码
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的节点

 

注意上面的方法 返回的是jquery 集合 需要继续用jq的方法操作或取值
如果想要转为dom 直接操作的只需要 取它的下标即可
如: $("#test1").parent()[0] 返回的就是dom节点
posted @ 2019-11-19 10:51  millet_handsome  阅读(29030)  评论(0编辑  收藏  举报